1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| public abstract class Voucher {
protected Process process;
protected String command, pathSource, pathTemporary, pathDestination;
protected File input, temporary, output;
protected OpenOfficeConnection connection;
protected FileOutputStream temporaryStream;
protected POIFSFileSystem fileSystem;
protected HSSFWorkbook workbook;
protected HSSFCell[][][] cells;
protected ArrayList contain;
protected int NBPAGES, NBROWONLASTPAGE, FIRSTLINE_FIRSTSHEET, LASTLINE_FIRSTSHEET, FIRSTLINE_OTHERSSHEETS,
LASTLINE_OTHERSSHEETS = LASTLINE_FIRSTSHEET,
FIRST_COLLUMN, SECONDCOLLUMN, THIRDCOLLUMN, FOURTHCOLLUMN, FIFTHCOLLUMN, SIXTHCOLLUMN, SEVENTHCOLLUMN, NBTOTALLINES, HEADSIZE;
protected Javarch javarch;
public Voucher() {JOptionPane.showMessageDialog(null, "Voucher");}
public Voucher (Javarch javarch, ArrayList contain, String pathSource, String pathTemporary, String pathDestination) {
JOptionPane.showMessageDialog(null, "Voucher");
this.javarch = javarch;
this.contain = contain;
this.command = "C:\\Program Files\\OpenOffice.org 3\\program\\soffice.exe -headless -accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager";
this.input = new File(pathSource);
this.temporary = new File(pathTemporary);
this.output = new File(pathDestination);
try {
FileInputStream fis;
fis = new FileInputStream(pathSource);
this.fileSystem = new POIFSFileSystem(fis);//convert to POI file
this.workbook = new HSSFWorkbook(fileSystem);//make a workbook (xls file contain)
}
catch (IOException ioe) {ioe.printStackTrace();}
JOptionPane.showMessageDialog(null, "FinVoucher");
}
public Voucher (Javarch javarch, String pathSource, String pathTemporary, String pathDestination) {
JOptionPane.showMessageDialog(null, "Voucher");
this.javarch = javarch;
this.command = "C:\\Program Files\\OpenOffice.org 3\\program\\soffice.exe -headless -accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager";
this.input = new File(pathSource);
this.temporary = new File(pathTemporary);
this.output = new File(pathDestination);
try {
this.fileSystem = new POIFSFileSystem(new FileInputStream(pathSource));//convert to POI file
this.workbook = new HSSFWorkbook(fileSystem);//make a workbook (xls file contain)
}
catch (IOException ioe) {ioe.printStackTrace();}
}
public Voucher (String pathSource, String pathTemporary, String pathDestination) {
JOptionPane.showMessageDialog(null, "Voucher");
this.command = "C:\\Program Files\\OpenOffice.org 3\\program\\soffice.exe -headless -accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager";
this.input = new File(pathSource);
this.temporary = new File(pathTemporary);
this.output = new File(pathDestination);
try {
this.fileSystem = new POIFSFileSystem(new FileInputStream(pathSource));//convert to POI file
this.workbook = new HSSFWorkbook(fileSystem);//make a workbook (xls file contain)
}
catch (IOException ioe) {ioe.printStackTrace();}
}
protected abstract void fill ();
protected abstract void initCells();
protected abstract void fillHeader();
protected abstract void fillContain();
/**
* After fill document, make a PDF file
*/
protected void generatePDF() {
try {this.process = Runtime.getRuntime().exec(command);}//run open ofice
catch (IOException ex) {}
// connect to an OpenOffice.org instance running on port 8100
JOptionPane.showMessageDialog(null, "0");
connection = new SocketOpenOfficeConnection(8100);
JOptionPane.showMessageDialog(null, "1");
try {connection.connect();}
catch (ConnectException ex) {ex.printStackTrace();}
//convert
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
converter.convert(temporary, output);
temporary.delete();
// close the connection
// connection.disconnect();
this.process.destroy();
} |
Partager