2

I have created an application which reads a worksheet from a xlsx file, It working fine , but how can we convert that worksheet into an external xlsx file

My code is as given below

InputStream is = new FileInputStream("C:/Users/Work/Desktop/ss1.xlsx");
Workbook wb = WorkbookFactory.create(is);
int i= wb.getNumberOfSheets();
System.out.println("No fo sheets:"+i);
Sheet sheet = wb.getSheetAt(0);
// how can we convert the sheet to another seperate xlsx file

I am using apache poi library

Alex Man
  • 4,746
  • 17
  • 93
  • 178
  • 2
    Think outside the box. Don't "convert" the sheet to a workbook. Create a new workbook, and add the sheet to that new workbook. – Rainbolt Jun 17 '14 at 19:06
  • Can you show me an example.... – Alex Man Jun 17 '14 at 19:09
  • I think there's plenty of samples that can help you [here](http://poi.apache.org/spreadsheet/how-to.html) – рüффп Jun 17 '14 at 19:16
  • Can you please give me some suggestion for this question http://stackoverflow.com/questions/24270546/missing-worksheet-and-page-size-issues-when-excel-convert-to-pdf-using-open-offi – Alex Man Jun 17 '14 at 19:22
  • 1
    If you must do it with Apache POI, then Google "POI copy worksheet between workbooks". You can't miss the mountains of code you get on the first page that all do the same thing. If you are up for using something else, take a look at [this](http://www.aspose.com/docs/display/cellsjava/Copying+and+Moving+Worksheets). – Rainbolt Jun 17 '14 at 19:26
  • What do you mean by external file?... If you want to save another excel file then just use `write` method and give the address of the file you want to save... – Sankumarsingh Jun 18 '14 at 07:02
  • @Sankumarsingh means i want to save that worksheet to an axternal excel file, with write how will i do that , can you show me an example – Alex Man Jun 18 '14 at 14:29

0 Answers0