Microsoft Excel dosyalarının Çalışma Sayfalarını yönetin.

Aspose.Cells bir sınıf sağlar,Çalışma kitabı Bu bir Excel dosyasını temsil eder. buÇalışma kitabısınıf bir içerirçalışma sayfalarıExcel dosyasındaki her çalışma sayfasına erişim sağlayan koleksiyon.

Bir çalışma sayfası şununla temsil edilir:Çalışma kağıdısınıf. buÇalışma kağıdıclass, çalışma sayfalarını yönetmek için çok çeşitli özellikler ve yöntemler sağlar.

Çalışma Sayfalarını Yeni Bir Excel Dosyasına Ekleme

Programlı olarak yeni bir Excel dosyası oluşturmak için:

  1. Şunun bir nesnesini oluşturun:Çalışma kitabısınıf.
  2. AraEklemek yöntemiÇalışma Sayfası Koleksiyonu sınıf. Excel dosyasına otomatik olarak boş bir çalışma sayfası eklenir. Yeni çalışma sayfasının sayfa dizini şuraya geçirilerek başvurulabilir:çalışma sayfaları Toplamak.
  3. Bir çalışma sayfası referansı edinin.
  4. Çalışma sayfaları üzerinde çalışma gerçekleştirin.
  5. Çağırarak yeni Excel dosyasını yeni çalışma sayfalarıyla kaydedin.Çalışma kitabı sınıf'Kayıt etmekyöntem.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
System.IO.Directory.CreateDirectory(dataDir);
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Adding a new worksheet to the Workbook object
int i = workbook.Worksheets.Add();
// Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[i];
// Setting the name of the newly added worksheet
worksheet.Name = "My Worksheet";
// Saving the Excel file
workbook.Save(dataDir + "output.out.xls");

Tasarımcı Elektronik Tablosuna Çalışma Sayfaları Ekleme

Bir tasarımcı elektronik tablosuna çalışma sayfası ekleme işlemi, Excel dosyasının zaten mevcut olması ve çalışma sayfaları eklenmeden önce açılması gerektiği dışında, yeni bir çalışma sayfası ekleme işlemiyle aynıdır. Bir tasarımcı e-tablosu şu şekilde açılabilir:Çalışma kitabısınıf.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
string InputPath = dataDir + "book1.xlsx";
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(InputPath, FileMode.Open);
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Adding a new worksheet to the Workbook object
int i = workbook.Worksheets.Add();
// Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = workbook.Worksheets[i];
// Setting the name of the newly added worksheet
worksheet.Name = "My Worksheet";
// Saving the Excel file
workbook.Save(dataDir + "output.xlsx");

Sayfa Adını Kullanarak Çalışma Sayfalarına Erişme

Adını veya dizinini belirterek herhangi bir çalışma sayfasına erişin.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
string InputPath = dataDir + "book1.xlsx";
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(InputPath, FileMode.Open);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Accessing a worksheet using its sheet name
Worksheet worksheet = workbook.Worksheets["Sheet1"];
Cell cell = worksheet.Cells["A1"];
Console.WriteLine(cell.Value);

Sayfa Adını Kullanarak Çalışma Sayfalarını Kaldırma

Çalışma sayfalarını bir dosyadan kaldırmak için,KaldırAt yöntemiÇalışma Sayfası Koleksiyonu sınıf. Sayfa adını şuraya iletin:KaldırAtbelirli bir çalışma sayfasını kaldırma yöntemi.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Removing a worksheet using its sheet name
workbook.Worksheets.RemoveAt("Sheet1");
// Save workbook
workbook.Save(dataDir + "output.out.xls");

Sayfa Dizini Kullanarak Çalışma Sayfalarını Kaldırma

Çalışma sayfalarını ada göre kaldırmak, çalışma sayfasının adı bilindiğinde işe yarar. Çalışma sayfasının adını bilmiyorsanız, aşırı yüklenmiş bir sürümünü kullanın.KaldırAtçalışma sayfasının sayfa adı yerine sayfa dizinini alan yöntem.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(dataDir + "book1.xls", FileMode.Open);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
// Removing a worksheet using its sheet index
workbook.Worksheets.RemoveAt(0);
// Save workbook
workbook.Save(dataDir + "output.out.xls");

Sayfaları Etkinleştirme ve Çalışma Sayfasında Cell Etkinleştirme

Bazen, bir kullanıcı bir Microsoft Excel dosyasını Excel’de açtığında belirli bir çalışma sayfasının etkin olması ve görüntülenmesi gerekir. Benzer şekilde, belirli bir hücreyi etkinleştirmek ve kaydırma çubuklarını etkin hücreyi gösterecek şekilde ayarlamak isteyebilirsiniz. Aspose.Cells tüm bu görevleri yapabilecek kapasitededir.

Biretkin sayfa üzerinde çalıştığınız bir sayfadır: sekmedeki etkin sayfanın adı varsayılan olarak kalındır.

Biraktif hücre seçili bir hücredir, yazmaya başladığınızda verilerin girildiği hücredir. Aynı anda yalnızca bir hücre etkindir. Etkin hücre kalın bir kenarlıkla vurgulanır.

Sayfaları Etkinleştirme ve Cell Etkinleştirme

Aspose.Cells, bir sayfa ve hücreyi etkinleştirmek için özel API çağrıları sağlar. Örneğin,Aspose.Cells.WorksheetCollection.ActiveSheetIndexözelliği, bir çalışma kitabındaki etkin sayfayı ayarlamak için kullanışlıdır. Benzer şekilde,Aspose.Cells.Worksheet.ActiveCellözelliği, çalışma sayfasında etkin bir hücre ayarlamak ve almak için kullanılır.

Yatay veya dikey kaydırma çubuklarının, belirli verileri göstermek istediğiniz satır ve sütun dizini konumunda olduğundan emin olmak için,Aspose.Cells.Worksheet.FirstVisibleRow veAspose.Cells.Worksheet.FirstVisibleColumnözellikler.

Aşağıdaki örnek, bir çalışma sayfasının nasıl etkinleştirileceğini ve içinde etkin bir hücrenin nasıl oluşturulacağını gösterir. Oluşturulan çıktıda, kaydırma çubukları kaydırılarak 2. sıra ve 2. sütun ilk görünür satır ve sütunları olur.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Instantiate a new Workbook.
Workbook workbook = new Workbook();
// Get the first worksheet in the workbook.
Worksheet worksheet1 = workbook.Worksheets[0];
// Get the cells in the worksheet.
Cells cells = worksheet1.Cells;
// Input data into B2 cell.
cells[1, 1].PutValue("Hello World!");
// Set the first sheet as an active sheet.
workbook.Worksheets.ActiveSheetIndex = 0;
// Set B2 cell as an active cell in the worksheet.
worksheet1.ActiveCell = "B2";
// Set the B column as the first visible column in the worksheet.
worksheet1.FirstVisibleColumn = 1;
// Set the 2nd row as the first visible row in the worksheet.
worksheet1.FirstVisibleRow = 1;
// Save the excel file.
workbook.Save(dataDir + "output.xls");

ileri konular