Microsoft® Conversione file Excel via Java
Salva i documenti Excel Microsoft come fogli di calcolo, Web, immagini e formati a layout fisso
Per ogniConvertitore Excel applicazione o soluzione, Java Excel Library velocizza la programmazione dei fogli di calcolo e i processi di conversione gestendo più formati tra cui XLS, XLSX, XLSM, XLSB, XLTX, XLTM, CSV, SpreadsheetML, 0761 93481. Consente inoltre di convertire i file Excel in PDF*, XPS, HTML, MHTML, testo semplice e formati di immagine popolari come TIFF, JPG, PNG, BMP e SVG.
Inter-conversione dei formati Excel Microsoft
L’inter-conversione del formato del foglio di calcolo richiede solo il caricamento di un foglio di calcolo con un’istanza di Cartella di lavoro e salvare nuovamente nel formato desiderato mentre si seleziona il valore appropriato da SalvaFormato enumerazione.
Java Esempio di codice per conversione formato file Excel
// load the source file
var wkb = new Workbook("sourceFile.xls");
// save as XLSX, ODS, SXC & FODS formats
wkb.save("xlsx-output.xlsx", SaveFormat.XLSX);
wkb.save("ods-output.ods", SaveFormat.ODS);
wkb.save("scx-output.scx", SaveFormat.SXC);
wkb.save("fods-output.fods", SaveFormat.FODS);
Converti Excel in PDF, XPS, HTML e MD
Sono disponibili classi specializzate per controllare il processo di conversione per formati di output specifici come PdfSaveOptions per convertire i file Excel come PDF, XpsSaveOptions per esportare Excel come XPS, HtmlSaveOptions per rendere Excel come HTML e MarkdownSaveOptions per la conversione da Excel a Markdown.
Java Codice di esempio per formati da Excel a PDF e Web
// load template Excel file from disc
var bk = new Workbook("source-file.xlsx");
// convert Excel to PDF using Java
// Create PDF options
PdfSaveOptions options = new PdfSaveOptions();
options.setCompliance(PdfCompliance.PDF_A_1_A);
bk.save("excel-to-pdf.pdf", options);
// save Excel in XPS
bk.save("output.xps", new XpsSaveOptions());
// save Excel in HTML
bk.save("output.html", new HtmlSaveOptions());
// save Excel in Markdown (MD)
bk.save("output.md", new MarkdownSaveOptions());
// one can set relevant save options as of his choice before saving into relevant format
Converti JSON in Excel ed Excel in JSON
JSON i dati possono essere importati in un’istanza della classe Workbook con l’aiuto di JSONUtility.importData per ulteriori elaborazioni o semplici conversioni in uno qualsiasi dei formati supportati. Allo stesso modo, i dati del foglio di lavoro possono essere esportati come JSON creando un file Allineare o celle e chiamando il exportRangeToJson metodo.
Java Codice per la conversione da JSON a Excel
Workbook workbook = new Workbook(path + "source-file.xlsx");
Worksheet wks = workbook.getWorksheets().get(0);
// Read File
File file = new File(path + "source-data.json");
BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
String jsonInput = "";
String tempString;
while ((tempString = bufferedReader.readLine()) != null) {
jsonInput = jsonInput + tempString;
}
bufferedReader.close();
// Set JsonLayoutOptions
JsonLayoutOptions options = new JsonLayoutOptions();
options.setIgnoreArrayTitle(true);
options.setArrayAsTable(true);
// Import JSON Data
JSONUtility.importData(jsonInput, wks.getCells(), 0, 0, options);
// Save Excel file
workbook.save(path + "excel-to-json.out.xlsx");
Java Codice sorgente per la conversione da Excel a JSON
// load XLSX file with an instance of Workbook
Workbook workbook = new Workbook("sourceFile.xlsx");
// access CellsCollection of the worksheet containing data to be converted
Cells cells = workbook.getWorksheets().get(0).getCells();
// create & set ExportRangeToJsonOptions for advanced options
ExportRangeToJsonOptions exportOptions = new ExportRangeToJsonOptions();
// create a range of cells containing data to be exported
Range range = cells.createRange(0, 0, cells.getLastCell().getRow() + 1, cells.getLastCell().getColumn() + 1);
// export range as JSON data
String jsonData = JsonUtility.exportRangeToJson(range, exportOptions);
// write data to disc in JSON format
BufferedWriter writer = new BufferedWriter(new FileWriter("output.json"));
writer.write(jsonData);
writer.close();
Salva fogli di lavoro Excel in immagini
Ogni foglio di lavoro può essere convertito in diversi formati di immagine tra cui JPG, BMP, PNG e GIF, impostati dalla proprietà ImageType. Per ogniConverti Excel in immagini caso, selezionare il caso pertinente dai collegamenti.
Java Codice per la conversione da Excel a immagine
// load template spreadsheet
var wkb = new Workbook("template.xlsx");
// Create an object for ImageOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
// Set the image type
imgOptions.setImageType(ImageType.PNG);
// Get the first worksheet.
Worksheet sheet = wkb.getWorksheets().get(0);
// Create a SheetRender object for the target sheet
SheetRender sr = new SheetRender(sheet, imgOptions);
for (int j = 0; j < sr.getPageCount(); j++) {
// Generate an image for the worksheet
sr.toImage(j, dataDir + "WToImage-out" + j + ".png");
}
Converti Microsoft Excel in Word e PowerPoint
È possibile caricare qualsiasi foglio di calcolo e convertirlo in file Word DOCX e PowerPoint PPTX durante l’utilizzo DocxSaveOptions & PptxSaveOptions classi come illustrato di seguito.
Java Codice per Excel in Word e PowerPoint Conversione
// load the template file
var wkb = new Workbook("template.xlsx");
// save spreadsheet as DOCX
wkb.save("output.docx", new DocxSaveOptions());
// save spreadsheet as PPTX
wkb.save("output.pptx", new PptxSaveOptions());