Mantener separadores para filas en blanco al exportar hojas de cálculo a formato CSV con JavaScript vía C++
Mantener separadores para filas en blanco al exportar hojas de cálculo a formato CSV
Aspose.Cells proporciona la capacidad de mantener los separadores de línea al convertir hojas de cálculo a formato CSV. Para esto, puede usar la propiedad TxtSaveOptions.keepSeparatorsForBlankRow de TxtSaveOptions. TxtSaveOptions.keepSeparatorsForBlankRow es una propiedad booleana. Para mantener los separadores de filas en blanco al convertir el archivo Excel a CSV, establezca la propiedad TxtSaveOptions.keepSeparatorsForBlankRow en true.
El siguiente código de ejemplo carga el archivo de Excel de origen. Establece la propiedad TxtSaveOptions.keepSeparatorsForBlankRow a true y lo guarda como output.csv. La captura de pantalla muestra la comparación entre el archivo Excel de origen, la salida predeterminada generada al convertir la hoja de cálculo a CSV y la salida generada al establecer TxtSaveOptions.keepSeparatorsForBlankRow en true.

Código de muestra
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells TxtSaveOptions Example</title>
</head>
<body>
<h1>TxtSaveOptions to CSV Example</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
<button id="runExample">Convert to CSV</button>
<a id="downloadLink" style="display: none;">Download Result</a>
<div id="result"></div>
</body>
<script src="aspose.cells.js.min.js"></script>
<script type="text/javascript">
const { Workbook, SaveFormat, TxtSaveOptions, Utils } = AsposeCells;
AsposeCells.onReady({
license: "/lic/aspose.cells.enc",
fontPath: "/fonts/",
fontList: [
"arial.ttf",
"NotoSansSC-Regular.ttf"
]
}).then(() => {
console.log("Aspose.Cells initialized");
});
document.getElementById('runExample').addEventListener('click', async () => {
const fileInput = document.getElementById('fileInput');
if (!fileInput.files.length) {
document.getElementById('result').innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
return;
}
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Create a Workbook object from the uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Instantiate TxtSaveOptions
const options = new TxtSaveOptions();
// Set KeepSeparatorsForBlankRow to true to show separators in blank rows
options.keepSeparatorsForBlankRow = true;
// Save the workbook to CSV using the options
const outputData = workbook.save(SaveFormat.CSV, options);
const blob = new Blob([outputData], { type: 'text/csv' });
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'output.csv';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download CSV File';
document.getElementById('result').innerHTML = '<p style="color: green;">File converted successfully! Click the download link to get the CSV file.</p>';
});
</script>
</html>