Through document format conversion, the needs for document operations in different office situations can be met. This article will introduce how to convert Excel documents to other common document formats. Through the method in this article, you can support the conversion of Excel into PDF, pictures, html, XPS, XML, CSV, PCL, ODS, PostScript, and different versions of Office Excel, such as version97-2003, version2007, version2010, version2013, version2016, etc. different document formats. This article takes the conversion of several document formats as examples to introduce specific conversion methods.
Tools used: Free Spire.XLS for Java (free version)
Jar file download and import:
Method 1: Download the jar file package from the official website. After downloading, unzip the file and import Spire.Xls.jar in the lib folder into the Java program. As shown below:
Method 2: Can be imported through the maven warehouse.
Java code example (for reference)
import com.spire.xls.*; public class ExcelToImg { public static void main(String[] args) { //加载Excel工作表 Workbook wb = new Workbook(); wb.loadFromFile("test.xlsx"); //获取工作表 Worksheet sheet = wb.getWorksheets().get(0); //调用方法将Excel工作表保存为图片 sheet.saveToImage("ToImg.png"); //调用方法,将指定Excel单元格数据范围保存为图片 //sheet.saveToImage("ToImg2.png",8,1,30,7); //调用方法将Excel保存为HTML sheet.saveToHtml("ToHtml.html"); //调用方法将Excel保存为XPS sheet.saveToFile("ToXPS.xps", String.valueOf(FileFormat.XPS)); //调用方法将Excel保存为CSV sheet.saveToFile("ToCSV.csv", String.valueOf(FileFormat.CSV)); //调用方法将Excel保存为XML sheet.saveToFile("ToXML.xml", String.valueOf(FileFormat.XML)); //调用方法将Excel保存为PostScript sheet.saveToFile("ToPostScript.postscript", String.valueOf(FileFormat.PostScript)); //调用方法将Excel保存为PCL sheet.saveToFile("ToPCL.pcl", String.valueOf(FileFormat.PCL)); } }
Document conversion result:
The above is the detailed content of How to convert Excel into pictures in Java?. For more information, please follow other related articles on the PHP Chinese website!