convertir un fichier excel au format pdf à l'aide de java, itext et PI API et de conserver les paramètres

J'ai un fichier Excel qui a 5 colonnes ayant quelques cellules fusionnées, les cellules vides, les dates et autres informations texte (fichier excel).

Je suis à la lecture de ce fichier à l'aide de POI API en java. Je suis capable de convertir le fichier en format pdf table à l'aide de la bibliothèque iText jar.

Mais, tout le format n'est pas copié dans le fichier pdf. (par exemple, la fusion des cellules dans une colonne, et mise en forme ou les paramètres sont tous partis).

Un simple tableau pdf est créé.

Comment puis-je conserver le même format que dans excel? (Je veux la copie exacte de la feuille excel en pdf)

Voici le code que j'utilise

     //First we read the Excel file in binary format into FileInputStream
FileInputStream input_document = new FileInputStream(new File("K:\\DCIN_TER\\DCIN_EPU2\\CIRCUIT FROM BRANCH\\RAINBOW ORDERS\\" + SONo.trim() + "\\" + SONo.trim() + " - Checklist.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
com.itextpdf.text.Document iText_xls_2_pdf = new com.itextpdf.text.Document();
PdfWriter.getInstance(iText_xls_2_pdf, new FileOutputStream("K:\\DCIN_TER\\DCIN_EPU2\\CIRCUIT FROM BRANCH\\RAINBOW ORDERS\\" + SONo.trim() + "\\" + SONo.trim() + " - Checklist.pdf"));
iText_xls_2_pdf.open();
//we have 5 columns in the Excel sheet, so we create a PDF table with 5 columns; Note: There are ways to make this dynamic in nature, if you want to.
PdfPTable my_table = new PdfPTable(5);
//We will use the object below to dynamically add new data to the table
PdfPCell table_cell;
//Loop through rows.
while(rowIterator.hasNext())
{
Row rowi = rowIterator.next();
Iterator<Cell> cellIterator = rowi.cellIterator();
while(cellIterator.hasNext())
{
Cell celli = cellIterator.next(); //Fetch CELL
switch(celli.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(celli.getStringCellValue()));
//move the code below to suit to your needs
my_table.addCell(table_cell);
break;
case Cell.CELL_TYPE_NUMERIC:
//Push the data from Excel to PDF Cell
table_cell = new PdfPCell(new Phrase("" + celli.getNumericCellValue()));
//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  

J'ai joint le fichier excel comme une image

convertir un fichier excel au format pdf à l'aide de java, itext et PI API et de conserver les paramètres

Hey, avez-vous résolu votre problème..vous pouvez essayer jodconverter.. j'ai eu le même problème.. j'ai utilisé cette lib et il fonctionne comme un charme avec très peu de morceau de code..
salut Sumeet, la conversion est aussi un fichier qui sera enregistré dans un dossier local vous avez mis en place? pouvez-vous tout simplement de convertir et d'obtenir le flux?
confrontée au même problème, le pdf généré est laid avec des tables sans frontière et ne rentre pas dans le fichier pdf de la fenêtre d'affichage.

OriginalL'auteur user1416631 | 2014-04-04