【GcExcel v5.2 新特性介绍】支持插入 SVG 图片
GCExcel V5.2之后,对SVG类型做了全面的支持,主要为以下三点:1. 支持区域Range转化为SVG文件;2. 支持文件插入SVG文件;
3. 支持使用SVG文件填充形状。
下面会详细介绍三个新特性的详细实现代码。
1. 支持区域Range转化为SVG文件
public static void rangeExportSvg() throws FileNotFoundException {
Workbook wb = new Workbook();
IWorksheet ws = wb.getWorksheets().get(0);
Object data = new Object[][] { { "Name", "City", "Birthday", "Eye color", "Weight", "Height" },
{ "Richard", "New York", new GregorianCalendar(1968, 5, 8), "Blue", 67, 165 },
{ "Nia", "New York", new GregorianCalendar(1972, 6, 3), "Brown", 62, 134 },
{ "Jared", "New York", new GregorianCalendar(1964, 2, 2), "Hazel", 72, 180 },
{ "Natalie", "Washington", new GregorianCalendar(1972, 7, 8), "Blue", 66, 163 },
{ "Damon", "Washington", new GregorianCalendar(1986, 1, 2), "Hazel", 76, 176 },
{ "Angela", "Washington", new GregorianCalendar(1993, 1, 15), "Brown", 68, 145 } };
// set two-dimension array value to range A1:F7
ws.getRange("A1:F7").setValue(data);
ws.getRange("A1:F7").getFont().setBold(true);
ws.getRange("A1:F7").getFont().setColor(Color.GetBlack());
ws.getRange("A1:F7").getBorders().setLineStyle(BorderLineStyle.DashDot);
ws.getRange("A1:F7").getBorders().setColor(Color.GetBlue());
FileOutputStream fos = new FileOutputStream("rangeSvg.svg");
ws.getRange("A1:F7").toImage(fos, ImageType.SVG);
}
最终导出SVG展示如下:
2. 支持工作簿插入SVG文件
public static void addSvgFile() throws IOException {
Workbook wb = new Workbook();
IWorksheet ws = wb.getWorksheets().get(0);
File file = new File("fegaussianblur1.svg");
FileInputStream fis = new FileInputStream(file);
ws.getShapes().addPictureInPixel(fis, ImageType.SVG, 0, 0, 300, 300);
wb.save("test.xlsx");
}导出文件效果如下所示:
3. 支持SVG文件填充形状
public static void shapeFillSvg() throws IOException {
Workbook wb = new Workbook();
IWorksheet ws = wb.getWorksheets().get(0);
File file = new File("fegaussianblur1.svg");
FileInputStream fis = new FileInputStream(file);
IShape shape = ws.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 200, 200);
shape.getFill().userPicture(fis, ImageType.SVG);
shape.getPictureFormat().setBrightness(0.6);
shape.getPictureFormat().setContrast(0.3);
wb.save("test.xlsx");
}
到处文件效果如下:
页:
[1]