You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by David Law <Da...@apconsult.de> on 2007/09/01 08:17:44 UTC

Re: AW: Change sheet order in a workbook

it worked fine for me.

A stupid question: you are looking in the right directory for the files?
(e.g. new FileInputStream("D:\\Temp\\apache.poi\\test.xls"))

Regards from the Odenwald,
DaveLaw

matthias.sondermann@sdm.de wrote:
> That's the way I already tried it. But there is something I am doing wrong because it still doesn't work.
>
> Let's assume I have an Excel-Workbook with three empty sheets called "aaa", "bbb" and "ccc".
> Now that is the code I use:
>
> HSSFWorkbook w = new HSSFWorkbook(new FileInputStream("test.xls"));
> w.setSheetOrder("ccc", 0);
> w.setSheetOrder("bbb", 1);
> w.setSheetOrder("aaa", 2);
>
> FileOutputStream fileOut = new FileOutputStream("test2.xls");
> w.write(fileOut);
> fileOut.close();
>
> At the end there is a new Excel-Workbook named test2.xls with three sheets, but still the order is "aaa", "bbb", "ccc". Why?
>
> Matthias
>
> -----Ursprüngliche Nachricht-----
> Von: apachemail@charter.net [mailto:apachemail@charter.net] 
> Gesendet: Dienstag, 28. August 2007 15:50
> An: POI Users List
> Cc: Sondermann, Matthias
> Betreff: Re: Change sheet order in a workbook
>
> It sounds like setSheetOrder is exactly what you need.  Let's say you have sheets named the following currently in the following order:
>
> Sheet1
> Sheet2
> Sheet3
>
> You want them to be in the following order:
>
> Sheet2
> Sheet3
> Sheet1
>
> You would make the following calls:
>
> workbook.setSheetOrder("Sheet2",0);
> workbook.setSheetOrder("Sheet3",1);
> workbook.setSheetOrder("Sheet1",2);
>
> ---- matthias.sondermann@sdm.de wrote: 
>   
>> Hi,
>>
>> how can I order the sheets in a workbook? I found the method setSheetOrder and it changes something inside the workbook but the update is not visible.
>>
>> Greetings from Germany
>> Matthias
>>     
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
>   

AW: AW: Change sheet order in a workbook

Posted by ma...@sdm.de.
Yes of course. Changing the sheet order is not the only thing I am doing on the workbook. But its the only thing that does not work. The suprising thing is that the inner representation which I inspected in debug mode does recognize the order modifications. The only (and most important) problem is that the generated XLS-file does not show the changes.

Best regards
Matthias

-----Ursprüngliche Nachricht-----
Von: David Law [mailto:David.Law@apconsult.de] 
Gesendet: Samstag, 1. September 2007 08:18
An: POI Users List
Betreff: Re: AW: Change sheet order in a workbook

it worked fine for me.

A stupid question: you are looking in the right directory for the files?
(e.g. new FileInputStream("D:\\Temp\\apache.poi\\test.xls"))

Regards from the Odenwald,
DaveLaw

matthias.sondermann@sdm.de wrote:
> That's the way I already tried it. But there is something I am doing wrong because it still doesn't work.
>
> Let's assume I have an Excel-Workbook with three empty sheets called "aaa", "bbb" and "ccc".
> Now that is the code I use:
>
> HSSFWorkbook w = new HSSFWorkbook(new FileInputStream("test.xls")); 
> w.setSheetOrder("ccc", 0); w.setSheetOrder("bbb", 1); 
> w.setSheetOrder("aaa", 2);
>
> FileOutputStream fileOut = new FileOutputStream("test2.xls"); 
> w.write(fileOut); fileOut.close();
>
> At the end there is a new Excel-Workbook named test2.xls with three sheets, but still the order is "aaa", "bbb", "ccc". Why?
>
> Matthias
>
> -----Ursprüngliche Nachricht-----
> Von: apachemail@charter.net [mailto:apachemail@charter.net]
> Gesendet: Dienstag, 28. August 2007 15:50
> An: POI Users List
> Cc: Sondermann, Matthias
> Betreff: Re: Change sheet order in a workbook
>
> It sounds like setSheetOrder is exactly what you need.  Let's say you have sheets named the following currently in the following order:
>
> Sheet1
> Sheet2
> Sheet3
>
> You want them to be in the following order:
>
> Sheet2
> Sheet3
> Sheet1
>
> You would make the following calls:
>
> workbook.setSheetOrder("Sheet2",0);
> workbook.setSheetOrder("Sheet3",1);
> workbook.setSheetOrder("Sheet1",2);
>
> ---- matthias.sondermann@sdm.de wrote: 
>   
>> Hi,
>>
>> how can I order the sheets in a workbook? I found the method setSheetOrder and it changes something inside the workbook but the update is not visible.
>>
>> Greetings from Germany
>> Matthias
>>     
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org For additional 
> commands, e-mail: user-help@poi.apache.org
>
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org