pom引入
<!-- poi 绘制图片 -->
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jcommon</artifactId>
<version>1.0.21</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.17</version>
</dependency>
<dependency>
<groupId>jfree</groupId>
<artifactId>jfreechart-experimental</artifactId>
<version>1.0.9</version>
</dependency>
excel内容
代码
import com.aspose.cells.ImageFormat;
import com.aspose.cells.ImageOrPrintOptions;
import com.aspose.cells.SheetRender;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;
public class TestImage {
public static void ConvertToImage (String filepath ,String picpath){
Workbook book = null;
try {
book = new Workbook(filepath);
Worksheet sheet = book.getWorksheets().get(0);
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.setImageFormat(ImageFormat.getJpeg());
imgOptions.setCellAutoFit(false);
imgOptions.setOnePagePerSheet(true);
SheetRender render = new SheetRender(sheet, imgOptions);
render.toImage(0, picpath);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String filepath = "E:/pic_test/text.xlsx";
String picpath = "E:/pic_test/1.png"; // jpg
TestImage.ConvertToImage(filepath, picpath);
}
}
发现没有表格线,是因为我们没有设置在excel中
在执行就好了