Apri file di versioni diverse di Microsoft Excel con Node.js tramite C++
Come aprire file di diverse versioni di Microsoft Excel
Un’applicazione spesso deve poter aprire file Microsoft Excel creati in versioni differenti, per esempio Microsoft Excel 95, 97, o Microsoft Excel 2007/2010/2013/2016/2019 e Office 365. Potrebbe essere necessario caricare un file in uno dei vari formati, inclusi XLS, XLSX, XLSM, XLSB, SpreadsheetML, TabDelimited o TSV, CSV, ODS e altri. Usa il costruttore, o specifica l’attributo di tipo getFileFormat() della classe Workbook che indica il formato usando l’enumerazione FileFormatType.
L’enumerazione FileFormatType contiene molti formati di file predefiniti, alcuni dei quali sono i seguenti.
Tipi di formato file | Descrizione |
---|---|
Csv | Rappresenta un file CSV |
Excel97To2003 | Rappresenta un file Excel 97 - 2003 |
Xlsx | Rappresenta un file XLSX Excel 2007/2010/2013/2016/2019 e Office 365 |
Xlsm | Rappresenta un file XLSM Excel 2007/2010/2013/2016/2019 e Office 365 |
Xltx | Rappresenta un file modello XLTX di Excel 2007/2010/2013/2016/2019 e Office 365 |
Xltm | Rappresenta un file XLTM macro abilitato di Excel 2007/2010/2013/2016/2019 e Office 365 |
Xlsb | Rappresenta un file XLSB binario di Excel 2007/2010/2013/2016/2019 e Office 365 |
SpreadsheetML | Rappresenta un file SpreadsheetML |
Tsv | Rappresenta un file di valori separati da tabulazioni |
TabDelimited | Rappresenta un file di testo delimitato da tabulazioni |
Ods | Rappresenta un file ODS |
Html | Rappresenta un file HTML |
Mhtml | Rappresenta un file MHTML |
Apri file Microsoft Excel 95/5.0
Per aprire un file Microsoft Excel 95/5.0, usa LoadOptions e imposta l’attributo correlato per la classe LoadOptions del file di modello da caricare. Un file di esempio per testare questa funzione può essere scaricato dal seguente link:
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, "Excel95_5.0.xls");
// Get the Excel file into stream
const stream = fs.readFileSync(filePath);
// Instantiate LoadOptions specified by the LoadFormat.
const loadOptions1 = new AsposeCells.LoadOptions(AsposeCells.LoadFormat.Auto);
// Create a Workbook object and opening the file from the stream
const wbExcel95 = new AsposeCells.Workbook(stream, loadOptions1);
console.log("Microsoft Excel 95/5.0 workbook opened successfully!");
Apri file Microsoft Excel 97 - 2003
Per aprire un file Microsoft Excel 97 - 2003, usa LoadOptions e imposta l’attributo correlato per la classe LoadOptions del file di modello da caricare.
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, "Book_Excel97_2003.xls");
// Get the Excel file into stream
const stream = fs.readFileSync(filePath);
// Instantiate LoadOptions specified by the LoadFormat.
const loadOptions1 = new AsposeCells.LoadOptions(AsposeCells.LoadFormat.Excel97To2003);
// Create a Workbook object and opening the file from the stream
const wbExcel97 = new AsposeCells.Workbook(stream, loadOptions1);
console.log("Microsoft Excel 97 - 2003 workbook opened successfully!");
Apri file XLSX di Microsoft Excel 2007/2010/2013/2016/2019 e Office 365
Per aprire un formato Microsoft Excel 2007/2010/2013/2016/2019 e Office 365, cioè XLSX o XLSB, specifica il percorso del file. Puoi anche usare LoadOptions e impostare gli attributi/opzioni correlati della classe LoadOptions per il file di modello da caricare.
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// The path to the documents directory.
const dataDir = path.join(__dirname, "data");
// Opening Microsoft Excel 2007 Xlsx Files
// Instantiate LoadOptions specified by the LoadFormat.
const loadOptions = new AsposeCells.LoadOptions(AsposeCells.LoadFormat.Xlsx);
// Create a Workbook object and opening the file from its path
const workbook = new AsposeCells.Workbook(path.join(dataDir, "Book_Excel2007.xlsx"), loadOptions);
console.log("Microsoft Excel 2007 - Office365 workbook opened successfully!");
Apri file Excel criptati
È possibile creare file Excel crittografati usando Microsoft Excel. Per aprire un file crittografato, usa LoadOptions e imposta i suoi attributi e opzioni (ad esempio, fornisce una password) per il file di modello da caricare. Un file di esempio per testare questa funzionalità può essere scaricato dal seguente link:
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, "encryptedBook.xls");
// Instantiate LoadOptions
const loadOptions = new AsposeCells.LoadOptions();
// Specify the password
loadOptions.setPassword("1234");
// Create a Workbook object and opening the file from its path
const wbEncrypted = new AsposeCells.Workbook(filePath, loadOptions);
console.log("Encrypted excel file opened successfully!");
Aspose.Cells supporta anche l’apertura di file Microsoft Excel 2007, 2010, 2013, 2016, 2019 e Office 365 protetti da password.