翻譯|使用教程|編輯:李顯亮|2021-03-12 10:21:44.860|閱讀 404 次
概述:Excel電子表格被廣泛用于存儲,組織和分析數(shù)據(jù)。在本文中,將學(xué)習(xí)如何使用Java將Excel XLSX / XLS文件轉(zhuǎn)換為PNG,JPEG,BMP和其他圖像格式。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Excel電子表格被廣泛用于存儲,組織和分析數(shù)據(jù)。但是,不能將Excel工作簿或工作表直接嵌入到Web或桌面應(yīng)用程序中。合適的選項(xiàng)之一是將工作表轉(zhuǎn)換為圖像或HTML格式。在本文中,將學(xué)習(xí)如何使用Java將Excel XLSX / XLS文件轉(zhuǎn)換為PNG,JPEG,BMP和其他圖像格式。
Aspose.Cells for Java是功能強(qiáng)大的電子表格處理API,可將工作表高質(zhì)量轉(zhuǎn)換為PNG,JPEG,BMP和其他流行的圖像格式。點(diǎn)擊下方按鈕可下載試用。
Aspose.Cells for Java支持將Excel文件轉(zhuǎn)換為以下圖像格式:
以下是將工作表轉(zhuǎn)換為PNG圖像的API引用步驟。
下面的代碼示例演示如何使用Java將Excel XLSX文件轉(zhuǎn)換為圖像。
// Load Excel file
Workbook workbook = new Workbook("workbook.xlsx");
// Create an object of ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
// Set the output image type
imgOptions.setImageType(ImageType.PNG);
// Get the first worksheet
Worksheet sheet = workbook.getWorksheets().get(0);
// Create a SheetRender object for the target sheet
SheetRender sr = new SheetRender(sheet, imgOptions);
for (int page = 0; page < sr.getPageCount(); page++) { // Generate an image for the worksheet sr.toImage(page, "image" + page + ".png"); }
Aspose.Cells for Java還提供了其他選項(xiàng),以自定義XLSX進(jìn)行圖像轉(zhuǎn)換。例如,您可以指定網(wǎng)格線的樣式,每張紙渲染一張圖像,等等。該ImageOrPrintOptions類用于設(shè)置這些選項(xiàng)。下面的代碼示例演示如何在Excel中使用ImageOrPrintOptions類進(jìn)行圖像轉(zhuǎn)換。
// Load Excel file
Workbook workbook = new Workbook("workbook.xlsx");
// Create an object of ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
// Set the image type
imgOptions.setImageType(ImageType.PNG);
// Set one page per sheet rendering
imgOptions.setOnePagePerSheet(true);
// Set gridline
imgOptions.setGridlineType(GridlineType.DOTTED);
// Get the first worksheet
Worksheet sheet = workbook.getWorksheets().get(0);
// Create a SheetRender object for the target sheet
SheetRender sr = new SheetRender(sheet, imgOptions);
for (int page = 0; page < sr.getPageCount(); page++) {
// Generate an image for the worksheet
sr.toImage(page, "image" + page + ".png");
}
如果你想試用Aspose的全部完整功能,可 聯(lián)系在線客服獲取30天臨時(shí)授權(quán)體驗(yàn)。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn