Openize.OpenXML-SDK for .NET
C# .NET Uygulamalarında Office Belgelerini Yönetme
Microsoft Office belgelerini, Word, Excel ve PowerPoint dosyalarını yalnızca birkaç satır kodla oluşturun, yükleyin ve düzenleyin.
Openize.OpenXML-SDK for .NET, Microsoft Office belgelerini zahmetsizce oluşturmak ve özelleştirmek için tasarlanmış kullanıcı dostu ve erişilebilir bir açık kaynak .NET SDK’sıdır. Bu sezgisel C# kütüphanesi, Word, Excel ve PowerPoint belgelerini minimum kod satırıyla oluşturmanıza ve düzenlemenize olanak tanır.
Hafif yapıya sahip bu çözümün kurulumu oldukça kolay olup, çeşitli belge ihtiyaçlarına uygun birçok özellik sunmaktadır. Openize.OpenXML-SDK, Microsoft tarafından desteklenen OpenXML SDK’nın gücünü kullanır. OpenXML'in gelişmiş yeteneklerinden yararlanmayı basitleştiren kullanışlı bir yardımcı araç olarak hizmet verir.
Geliştiriciler düşünülerek tasarlanan bu açık kaynak .NET kütüphanesi, OpenXML SDK’nın işlevselliğini genişletme imkanı sunar. Kullanıcı dostu yapısı sayesinde, yeni paragraflar ekleme, metin formatlama, resim ekleme ve boyutlandırma, resim çıkarma, belge özelliklerini değiştirme gibi birçok akıllı özelliğe sahiptir.
Açık kaynak SDK’mızı geliştirmek, önerilerde bulunmak ve katkıda bulunmak için GitHub depomuzu ziyaret edin: https://github.com/openize-com/openize-open-xml-sdk-net
Openize.OpenXML-SDK for .NET ile Başlarken
Openize.OpenXML-SDK for .NET'i yüklemenin önerilen yolu NuGet kullanmaktır. Sorunsuz bir kurulum için lütfen aşağıdaki komutu kullanın.
Openize.OpenXML-SDK for .NET’i NuGet ile Yükleme
NuGet\Install-Package Openize.OpenXML-SDK
Ayrıca doğrudan GitHub üzerinden de indirebilirsiniz.Programlı Olarak Bir Word Belgesi Oluşturma
Aşağıdaki kod örneği, programlı olarak boş bir Word belgesi oluşturmayı göstermektedir.
.NET SDK ile Word Belgesi Oluşturma
// Create an instance of the Document class.
Document doc = new Document();
// Invoke the Save method to save the Word document onto the disk.
doc.Save("/Docs.docx");
Bir Word Belgesine Metin Ekleme
Aşağıdaki kod örneği, programlı olarak bir belgeye metin eklemeyi göstermektedir.
.NET SDK ile Word Belgesine Paragraf Ekleme
// Create an instance of the Document class.
using (Document doc = new Document())
{
//Initialize the constructor with the Document class object.
Body body = new Body(doc);
// Instantiate an instance of the Paragraph class.
Paragraph para1 = new Paragraph();
// Set the text of the paragraph.
para1.AddRun(new Run { Text = "This is a Paragraph." });
// Invoke AppendChild method of the body class to add a paragraph to the document.
body.AppendChild(para1);
// Call the Save method to save the Word document onto the disk.
doc.Save("/Docs.docx");
}
Programlı Olarak Boş Bir Excel Çalışma Kitabı (Workbook) Oluşturma
Aşağıdaki kod örneği, C# ve FileFormat.Cells kütüphanesini kullanarak yeni bir Microsoft Excel elektronik tablosu oluşturmayı ve kaydetmeyi göstermektedir.
- FileFormat.Cells kütüphanesi içe aktarılır ve Excel elektronik tabloları ile çalışmaya olanak tanır.
- Example ad alanı (namespace) içinde Program sınıfı tanımlanır.
- Main metodu, programın başlangıç noktasıdır ve komut satırı argümanlarını (string[] args) kabul eder.
- Workbook sınıfının bir örneği `Workbook workbook = new Workbook();` ile başlatılır.
- Save metodu çağrılarak elektronik tablo kaydedilir. Dosya, kök dizinde "/" içine "Spreadsheet.xlsx" adıyla kaydedilir.
Aşağıdaki kodu ana dosyanıza kopyalayıp yapıştırın ve programı çalıştırın.
C# ile Boş Bir Çalışma Kitabı / Elektronik Tablo Oluşturma
using System;
using Openize.Cells;
namespace Example
{
class Program
{
static void Main(string[] args)
{
// Initialize an instance of the Workbook class.
var workbook = new Openize.Cells.Workbook();
// Call the Save method to save the MS Excel Spreadsheet/Workbook onto the disk.
workbook.Save("Z:\\Downloads\\Spreadsheet.xlsx");
Console.WriteLine("Excel spreadsheet created successfully.");
}
}
}
Excel Çalışma Sayfasına Belirli Bir Satır İndeksinde Satır Ekleme
Bu C# örneği, Openize.Cells kütüphanesini kullanarak bir Excel çalışma sayfasına belirli bir satır indeksinde nasıl satır ekleneceğini göstermektedir.
Aşağıdaki kodu ana dosyanıza kopyalayıp yapıştırın ve programı çalıştırın.
C# ile Excel Dosyasına Satır Ekleme
using System;
using Openize.Cells;
class Program
{
static void Main(string[] args)
{
string filePath = "Z:\\Downloads\\test_spreadsheet.xlsx";
// Load the workbook from the specified file path
using (var wb = new Openize.Cells.Workbook(filePath))
{
// Access the first worksheet in the workbook
var firstSheet = wb.Worksheets[0];
// Define the starting row index and the number of rows to insert
uint startRowIndex = 5;
uint numberOfRows = 3;
// Insert the rows into the worksheet
firstSheet.InsertRows(startRowIndex, numberOfRows);
// Get the total row count after insertion
int rowsCount = firstSheet.GetRowCount();
// Output the updated row count to the console
Console.WriteLine("Rows Count=" + rowsCount);
// Save the workbook to reflect the changes made
wb.Save(filePath);
Console.WriteLine("Rows inserted and workbook saved successfully.");
}
}
}
Programlı Olarak Bir PowerPoint Sunumu Oluşturma
Aşağıdaki kod örneği, programlı olarak boş bir PowerPoint sunumu oluşturmayı göstermektedir.
.NET API ile PowerPoint Sunumu Oluşturma
// Create an object of the Presentation class.
Presentation presentation = Presentation.Create("presentation.pptx");
//Perform necessary operations.
//...
// Call the Save method to save the PowerPoint file onto the disk.
presentation.Save();
Programlı Olarak PowerPoint Sunumuna Metin Ekleme
Aşağıdaki kod örneği, programlı olarak bir PowerPoint sunumuna nasıl metin ekleneceğini göstermektedir.
.NET API ile PowerPoint Sunumuna Metin Ekleme
// Create a new PowerPoint presentation at the specified file path
Presentation presentation = Presentation.Create("D:\\AsposeSampleResults\\test2.pptx");
// Create a text shape for the title and set its properties
TextShape shape = new TextShape();
shape.Text = "Title: Here is my first title From FF";
shape.TextColor = "980078";
shape.FontFamily = "Baguet Script";
// Create the slide and add the text shape to it
Slide slide = new Slide();
slide.AddTextShapes(shape);
// Append the slide to the presentation
presentation.AppendSlide(slide);
// Save the modified presentation
presentation.Save();
Daha Fazla Kod Örneği ve Kaynaklar
Daha fazla ayrıntılı kod örneği keşfetmek için Openize Gists adresini ziyaret edin.