Node.js ve C++ aracılığıyla Satır ve Sütunları Biçimlendirin
Satırlarla Çalışmak
Satır Yüksekliğini Ayarlamak
Aspose.Cells, Microsoft Excel dosyasını temsil eden Workbook adlı bir sınıf sağlar. Workbook sınıfı, Excel dosyasındaki her çalışma sayfasına erişim sağlayan WorksheetCollection adlı bir özelliğe sahiptir. Bir çalışma sayfası, Worksheet sınıfı ile temsil edilir. Worksheet sınıfı, çalışma sayfasındaki tüm hücreleri temsil eden bir Cells koleksiyonu sağlar.
Cells koleksiyonu, bir çalışma sayfasında satır veya sütunları yönetmek için çeşitli yöntemler sağlar. Bunlardan bazıları aşağıda daha ayrıntılı olarak tartışılmıştır.
Bir Satırın Yüksekliğini Ayarlama
Yalnızca bir satırın yüksekliğini Cells koleksiyonunun setRowHeight(number, number) yöntemi çağrılarak ayarlamak mümkündür. setRowHeight(number, number) yöntemi aşağıdaki parametreleri alır:
- Satır dizini, yüksekliği değiştirdiğiniz satırın dizini.
- Satır yüksekliği, satıra uygulanan satır yüksekliği.
try {
const path = require("path");
const fs = require("fs");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "book1.xls");
// Creating a file stream containing the Excel file to be opened
const fstream = fs.createReadStream(filePath);
// Reading the file stream into a buffer
const chunks = [];
fstream.on('data', chunk => chunks.push(chunk));
fstream.on('end', () => {
const buffer = Buffer.concat(chunks);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
const workbook = new AsposeCells.Workbook(buffer);
// Accessing the first worksheet in the Excel file
const worksheet = workbook.getWorksheets().get(0);
// Setting the height of the second row to 13
worksheet.getCells().setRowHeight(1, 13);
// Saving the modified Excel file
workbook.save(path.join(dataDir, "output.out.xls"));
// Closing the file stream to free all resources
fstream.close();
Bir Çalışma Sayfasındaki Tüm Satırların Yüksekliğini Ayarlama
Eğer geliştiriciler, çalışma sayfasındaki tüm satırlar için aynı satır yüksekliğini ayarlamak isterse, bunu Cells koleksiyonunun getStandardHeight() özelliğini kullanarak yapabilirler.
Örnek:
const fs = require("fs");
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "book1.xls");
// Creating a file stream containing the Excel file to be opened
const fstream = fs.readFileSync(filePath);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
const workbook = new AsposeCells.Workbook(fstream);
// Accessing the first worksheet in the Excel file
const worksheet = workbook.getWorksheets().get(0);
// Setting the height of all rows in the worksheet to 15
worksheet.getCells().setStandardHeight(15);
// Saving the modified Excel file
workbook.save(path.join(dataDir, "output.out.xls"));
// Closing the file stream to free all resources
// (Note: Closing the file stream is unnecessary in this context as it's a
// synchronous read performed using fs.readFileSync, which does not require
// explicit closure, but if using fs.createReadStream, you would handle it accordingly)
Sütunlarla Çalışmak
Bir Sütunun Genişliğini Ayarlama
Bir sütunun genişliğini Cells koleksiyonunun setColumnWidth(number, number) yöntemi çağrılarak ayarlayın. setColumnWidth(number, number) yöntemi aşağıdaki parametreleri alır:
- Sütun dizini, genişliği değiştirdiğiniz sütunun dizini.
- Sütun genişliği, istenen sütun genişliği.
const fs = require("fs");
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
const filePath = path.join(dataDir, "book1.xls");
// Creating a file stream containing the Excel file to be opened
const fstream = fs.readFileSync(filePath);
// Instantiating a Workbook object
// Opening the Excel file through the file stream
const workbook = new AsposeCells.Workbook(fstream);
// Accessing the first worksheet in the Excel file
const worksheet = workbook.getWorksheets().get(0);
// Setting the width of the second column to 17.5
worksheet.getCells().setColumnWidth(1, 17.5);
// Saving the modified Excel file
workbook.save(path.join(dataDir, "output.out.xls"));
// Closing the file stream to free all resources
fstream; // Note: No explicit close needed for fs.readFileSync
Piksel cinsinden Sütun Genişliğini Ayarlama
Bir sütunun genişliğini Cells koleksiyonunun setColumnWidthPixel(number, number) yöntemi çağrılarak ayarlayın. setColumnWidthPixel(number, number) yöntemi aşağıdaki parametreleri alır:
- Sütun dizini, genişliği değiştirdiğiniz sütunun dizini.
- Sütun genişliği, pikseller cinsinden istenen sütun genişliği.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// Source directory
const sourceDir = path.join(__dirname, "data");
const outDir = path.join(__dirname, "output");
// Load source Excel file
const workbook = new AsposeCells.Workbook(path.join(sourceDir, "Book1.xlsx"));
// Access first worksheet
const worksheet = workbook.getWorksheets().get(0);
// Set the width of the column in pixels
worksheet.getCells().setColumnWidthPixel(7, 200);
workbook.save(path.join(outDir, "SetColumnWidthInPixels_Out.xlsx"));
Bir Çalışma Sayfasındaki Tüm Sütunların Genişliğini Ayarlama
Tüm sütunlar için aynı sütun genişliğini ayarlamak için, Cells koleksiyonunun getStandardWidth() özelliğini kullanın.
const path = require("path");
const fs = require("fs");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Creating a file stream containing the Excel file to be opened
const filePath = path.join(dataDir, "book1.xls");
// Instantiating a Workbook object
// Opening the Excel file
const workbook = new AsposeCells.Workbook(filePath);
// Accessing the first worksheet in the Excel file
const worksheet = workbook.getWorksheets().get(0);
// Setting the width of all columns in the worksheet to 20.5
worksheet.getCells().setStandardWidth(20.5);
// Saving the modified Excel file
workbook.save(path.join(dataDir, "output.out.xls"));
// Closing the file stream to free all resources
// No explicit close needed in Node.js
Gelişmiş Konular
- Satır ve Sütunları Otomatik Sığdır
- Aspose.Cells Kullanarak Metni Sütunlara Dönüştürme
- Satırları ve Sütunları Kopyalama
- Çalışma Sayfasındaki Boş Satırları ve Sütunları Silme
- Satır ve Sütunları Gruplama ve Grubu Kaldırma
- Satır ve Sütunları Gizleme ve Gösterme
- Excel Çalışma Sayfasına Satır Eklemek veya Silmek
- Excel dosyasının Satır ve Sütunlarını Eklemek ve Silmek
- Çalışma Sayfasındaki Yinelemeli Satırları Kaldırma
- Çalışma sayfasında boş sütunları ve satırları silerken diğer çalışma sayfalarındaki referansları güncelle