package com.seamwhole.gcexcel.controller;
import com.grapecity.documents.excel.IWorksheet;
import com.grapecity.documents.excel.PdfSaveOptions;
import com.grapecity.documents.excel.SaveFileFormat;
import com.grapecity.documents.excel.Workbook;
import com.grapecity.documents.excel.drawing.IBackgroundPicture;
import com.grapecity.documents.excel.drawing.ImageLayout;
import com.grapecity.documents.excel.drawing.ImageType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;
@RestController
@RequestMapping("/gc-excel")
public class GCExcelController {
@GetMapping("load")
public void loadPdf(){
Path path = Paths.get("E:\\download\\aau.ssjson");
StringBuilder sb = new StringBuilder();
try (Stream<String> stream = Files.lines(path)) {
stream.forEach(s -> sb.append(s).append("\n"));
} catch (IOException ex) {
ex.printStackTrace();
}
String json= sb.toString();
Workbook workbook=new Workbook();
workbook.fromJson(json);
FileOutputStream outputStream = null;
IBackgroundPicture picture = null;
try {
//InputStream stream = getResourceStream("logo.png");
//IWorksheet worksheet = workbook.getWorksheets().get(0);
//worksheet.getRange("C40").setValue("对方水电费");
// worksheet.getShapes().addPictureInPixel(stream, ImageType.PNG, 10, 20, 500, 370);
//picture = worksheet.getBackgroundPictures().addPicture(stream, ImageType.PNG, 12, 18, 144, 167);
//Set image layout
//picture.setBackgroundImageLayout(ImageLayout.Zoom);
outputStream = new FileOutputStream("E:\\download\\au.pdf");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
workbook.save(outputStream, SaveFileFormat.Pdf);
// Close the file stream
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private InputStream getResourceStream(String resource) throws Exception {
return GCExcelController.class.getClassLoader().getResourceAsStream(resource);
}
}
==================================================================================================
package com.seamwhole.gcexcel;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class GcexcelApplication {
public static void main(String[] args) {
SpringApplication.run(GcexcelApplication.class, args);
}
}
|