文檔首頁>>Spire.XLS 系列教程>>Spire.XLS教程:在Java中以編程方式將Excel轉(zhuǎn)換為SVG
Spire.XLS教程:在Java中以編程方式將Excel轉(zhuǎn)換為SVG
Spire.XLS for Java是專業(yè)的Java Excel API,使開發(fā)人員無需使用Microsoft Office或Microsoft Excel即可創(chuàng)建,管理,操作,轉(zhuǎn)換和打印Excel工作表。
本文將演示如何在Java應(yīng)用程序中使用Spire.XLS for Java將Excel轉(zhuǎn)換為SVG流。
代碼如下:
import com.spire.xls.*; import java.io.FileOutputStream; import java.util.List; import java.util.Map; public class ExceltoSVG { public static void main(String[] args) throws Exception { //Load the sample document Workbook workbook = new Workbook(); workbook.loadFromFile("Sample.xlsx"); int count = 1; //Get the page split info. List> pageInfoList = workbook.getSplitPageInfo(); for (int i = 0; i < workbook.getWorksheets().getCount(); i++) { FileOutputStream stream; Worksheet sheet = workbook.getWorksheets().get(i); Map integerPageColRowMap = pageInfoList.get(i); for (Map.Entry entry : integerPageColRowMap.entrySet()) { PageColRow colRow = entry.getValue(); stream=new FileOutputStream("output/out" + (count++) + ".svg"); //Save to SVG sheet.toSVGStream(stream, colRow.StartRow, colRow.StartCol, colRow.EndRow, colRow.EndCol); stream.flush(); stream.close(); } } } }
輸出結(jié)果: