2017-05-11 4 views
-5

Ich muss 74 Blätter aus einem Excel-Dokument extrahieren und alle in 74 PDFs konvertieren. Ich muss auch mit einer SQL-Datenbank vergleichen, wenn der Name mit einem konkreten Feld meiner Datenbank übereinstimmt, aber das sollte kein Problem sein ... Jemand kann eine Bibliothek, die ich verwenden könnte, kennen? Ich habe eine Weile gesucht, aber ich finde die Lösung nicht, hoffe ihr könnt mir helfen! Vielen Dank.Konvertieren von konkreten Excel-Tabellen zu PDF mit Java

+1

Bitte fragen Sie nicht für Off-Site-Tool, Bibliotheken etc. Sie sind vom Thema. Weitere Hilfe zum Schreiben von guten Fragen finden Sie auf der [ask] Seite. – ItamarG3

+0

Sorry, wollte nur wissen, wie das geht, oder so etwas, weil das mich verrückt macht. – whitepab

+0

Sie sollten nach Google suchen. Wenn Sie dann Schwierigkeiten haben, die gefundenen Tools zu verwenden, können Sie spezifische Hilfe zu diesen spezifischen Tools anfordern. – ItamarG3

Antwort

0

Sie können aus diesem Code versuchen

public static void main(String[] args) throws Exception{ 
     //First we read the Excel file in binary format into FileInputStream 
     FileInputStream input_document = new FileInputStream(new File("C:\\excel_to_pdf.xls")); 
     // Read workbook into HSSFWorkbook 
     HSSFWorkbook my_xls_workbook = new HSSFWorkbook(input_document); 
     // Read worksheet into HSSFSheet 
     HSSFSheet my_worksheet = my_xls_workbook.getSheetAt(0); 
     // To iterate over the rows 
     Iterator<Row> rowIterator = my_worksheet.iterator(); 
     //We will create output PDF document objects at this point 
     Document iText_xls_2_pdf = new Document(); 
     PdfWriter.getInstance(iText_xls_2_pdf, new FileOutputStream("Excel2PDF_Output.pdf")); 
     iText_xls_2_pdf.open(); 
     //we have two columns in the Excel sheet, so we create a PDF table with two columns 
     //Note: There are ways to make this dynamic in nature, if you want to. 
     PdfPTable my_table = new PdfPTable(2); 
     //We will use the object below to dynamically add new data to the table 
     PdfPCell table_cell; 
     //Loop through rows. 
     while(rowIterator.hasNext()) { 
       Row row = rowIterator.next(); 
       Iterator<Cell> cellIterator = row.cellIterator(); 
         while(cellIterator.hasNext()) { 
           Cell cell = cellIterator.next(); //Fetch CELL 
           switch(cell.getCellType()) { //Identify CELL type 
             //you need to add more code here based on 
             //your requirement/transformations 
           case Cell.CELL_TYPE_STRING: 
             //Push the data from Excel to PDF Cell 
             table_cell=new PdfPCell(new Phrase(cell.getStringCellValue())); 
             //feel free to move the code below to suit to your needs 
             my_table.addCell(table_cell); 
             break; 
           } 
           //next line 
         } 

     } 
     //Finally add the table to PDF document 
     iText_xls_2_pdf.add(my_table);      
     iText_xls_2_pdf.close();     
     //we created our pdf file.. 
     input_document.close(); //close xls 
+0

Dies erklärt nichts über Ihre Antwort, oder warum es funktionieren könnte, was es tut oder verwendet. Vielleicht möchten Sie diese hinzufügen. – ItamarG3

+0

Vielen Dank! Ich mache es sofort und poste die Ergebnisse. Verwenden Sie den ITEXT-Treiber? – whitepab

Verwandte Themen