Node.js kullanarak Excel i CSV, TSV ve Txt ye dönüştürün
Workbook’u Metin veya CSV Formatında Kaydet
Bazen, bir çalışma kitabındaki birden çok sayfayı metin formatına dönüştürmek veya kaydetmek istersiniz. Metin formatları (örneğin TXT, TabDelim, CSV vb.) için, varsayılan olarak, hem Microsoft Excel hem de Aspose.Cells yalnızca aktif sayfanın içeriğini kaydeder.
Aşağıdaki kod örneği, tüm çalışma kitabını metin formatında kaydetmeyi açıklar. Kaynak çalışma kitabını yükleyin; bu, herhangi bir Microsoft Excel veya OpenOffice elektronik tablo dosyası olabilir (XLS, XLSX, XLSM, XLSB, ODS vb.) ve herhangi sayfa sayısına sahip olabilir.
Kod çalıştırıldığında, çalışma kitabındaki tüm sayfaların verilerini TXT formatına dönüştürür.
Aynı örneği CSV’ye kaydetmek için değiştirebilirsiniz. Varsayılan olarak, TxtSaveOptions.getSeparator() bir virgüldür, bu nedenle CSV biçimine kaydederken bir ayraç belirtmeyin.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Load your source workbook
const workbook = new AsposeCells.Workbook(path.join(dataDir, "book1.xls"));
// Text save options. You can use any type of separator
const opts = new AsposeCells.TxtSaveOptions();
opts.setSeparator('\t');
opts.setExportAllSheets(true);
// Save entire workbook data into file
workbook.save(path.join(dataDir, "out.txt"), opts);
Özel Ayraçla Metin Dosyaları Kaydetme
Metin dosyaları, biçimlendirme olmadan elektronik tablo verisi içerir. Dosya, verileri arasında özelleştirilmiş sınıflandırıcılara sahip bir düz metin dosyası türündedir.
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.xlsx");
// Create a Workbook object and opening the file from its path
const wb = new AsposeCells.Workbook(filePath);
// Instantiate Text File's Save Options
const options = new AsposeCells.TxtSaveOptions();
// Specify the separator
options.setSeparator(";");
// Save the file with the options
wb.save(path.join(dataDir, "output.csv"), options);