You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Jan Richter <jr...@gmail.com> on 2010/03/11 19:58:39 UTC

HSSF: HSSFSheet.setColumnWidth() has no effect

Hi,

if i call HSSFSheet.setColumnWidth() prior to creating any rows or cells
the setColumnWidth() work. If i call it after i created my rows and
cells it do not work.

Is this a bug or a feature?


I'm using POI 3.6

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


Re: HSSF: HSSFSheet.setColumnWidth() has no effect

Posted by MSB <ma...@tiscali.co.uk>.
Hello Jan,

I would have expected the method to work successfully whether you call it
before or after creating rows/colums and there is certainly no note in the
Javadocs indicating that the sequence is important. Can you create a simple
test file that demonstrates the problem - say a workbook with two sheets, on
one sheet call the setColumnWidth() method then create a row and cell and on
the other sheet create a row and cell then call setColumnWidth(). Hopefully,
one will work successfully and the other will fail and this file will give
the developers something to use in order to diagnose the problem. In
addition, could you say which version of POI you are using, which version of
Java and what you are runing the api on please; Windows, Linux, etc.

Yours

Mark B

PS Will have a play today if I have the time and see if anything obvious
leaps out at me.


Jan Richter wrote:
> 
> Hi,
> 
> if i call HSSFSheet.setColumnWidth() prior to creating any rows or cells
> the setColumnWidth() work. If i call it after i created my rows and
> cells it do not work.
> 
> Is this a bug or a feature?
> 
> 
> I'm using POI 3.6
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/HSSF%3A-HSSFSheet.setColumnWidth%28%29-has-no-effect-tp27868222p27874089.html
Sent from the POI - User mailing list archive at Nabble.com.


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


Re: HSSF: HSSFSheet.setColumnWidth() has no effect

Posted by Jan Richter <jr...@gmail.com>.
Hi Mark,

thanks for your reply.

Your test is running as expected in my setup. I'm currently trying to
extract the problematic code from my application..this may take a while ;)



> Hello again Jan,
> 
> I suspect there may be other problems because I cannot reproduce your
> results. This morning, I put together some test code that allowed me to test
> when I called the setColumnWidth(int, int) method and could not make it fail
> in the way you described. This is my test code;
> 
>         File outputFile = null;
>         FileOutputStream fos = null;
>         HSSFWorkbook workbook = null;
>         HSSFSheet sheet = null;
>         HSSFRow row = null;
>         HSSFCell cell = null;
>         try {
>             outputFile = new File("C:/temp/Column Test.xls");
>             fos = new FileOutputStream(outputFile);
> 
>             workbook = new HSSFWorkbook();
>             sheet = workbook.createSheet("Column Test.");
>             
>             //sheet.setColumnWidth(0, 1000);
>             
>             row = sheet.createRow(0);
>             cell = row.createCell(0);
>             cell.setCellValue("Just as a test.");
> 
>             sheet.setColumnWidth(0, 5000);
> 
>             workbook.write(fos);
>         }
>         catch(IOException ioEx) {
>             System.out.println("Caught an: " + ioEx.getClass().getName());
>             System.out.println("Message: " + ioEx.getMessage());
>             System.out.println("Stacktrace follows:.....");
>             ioEx.printStackTrace(System.out);
>         }
>         finally {
>             if(fos != null) {
>                 try {
>                     fos.close();
>                 }
>                 catch(IOException ioEx) {
>                     // Ignore - too late to recover anything now.
>                 }
>             }
>         }
> 
> Which, as you can see has the setColumnWidth(int, int) method in two places,
> before any cells are created and after. Whenevr I call the method it works;
> you can try this out for yourself, just comment and un-comment the code to
> use the respective calls.
> 
> Yours
> 
> Mark B
> 
> 
> Jan Richter wrote:
>> Hi,
>>
>> if i call HSSFSheet.setColumnWidth() prior to creating any rows or cells
>> the setColumnWidth() work. If i call it after i created my rows and
>> cells it do not work.
>>
>> Is this a bug or a feature?
>>
>>
>> I'm using POI 3.6
>>
>> ---------------------------------------------------------------------
>> 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


Re: HSSF: HSSFSheet.setColumnWidth() has no effect

Posted by MSB <ma...@tiscali.co.uk>.
Hello again Jan,

I suspect there may be other problems because I cannot reproduce your
results. This morning, I put together some test code that allowed me to test
when I called the setColumnWidth(int, int) method and could not make it fail
in the way you described. This is my test code;

        File outputFile = null;
        FileOutputStream fos = null;
        HSSFWorkbook workbook = null;
        HSSFSheet sheet = null;
        HSSFRow row = null;
        HSSFCell cell = null;
        try {
            outputFile = new File("C:/temp/Column Test.xls");
            fos = new FileOutputStream(outputFile);

            workbook = new HSSFWorkbook();
            sheet = workbook.createSheet("Column Test.");
            
            //sheet.setColumnWidth(0, 1000);
            
            row = sheet.createRow(0);
            cell = row.createCell(0);
            cell.setCellValue("Just as a test.");

            sheet.setColumnWidth(0, 5000);

            workbook.write(fos);
        }
        catch(IOException ioEx) {
            System.out.println("Caught an: " + ioEx.getClass().getName());
            System.out.println("Message: " + ioEx.getMessage());
            System.out.println("Stacktrace follows:.....");
            ioEx.printStackTrace(System.out);
        }
        finally {
            if(fos != null) {
                try {
                    fos.close();
                }
                catch(IOException ioEx) {
                    // Ignore - too late to recover anything now.
                }
            }
        }

Which, as you can see has the setColumnWidth(int, int) method in two places,
before any cells are created and after. Whenevr I call the method it works;
you can try this out for yourself, just comment and un-comment the code to
use the respective calls.

Yours

Mark B


Jan Richter wrote:
> 
> Hi,
> 
> if i call HSSFSheet.setColumnWidth() prior to creating any rows or cells
> the setColumnWidth() work. If i call it after i created my rows and
> cells it do not work.
> 
> Is this a bug or a feature?
> 
> 
> I'm using POI 3.6
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/HSSF%3A-HSSFSheet.setColumnWidth%28%29-has-no-effect-tp27868222p27874134.html
Sent from the POI - User mailing list archive at Nabble.com.


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


RE: Support for HSSF(.xls) in BigGridDemo

Posted by Mamatha Kodigehalli Venkatesh <Ma...@ness.com>.
Thanks Nick for quick feedback.
Also any inputs on how to achieve apply Formula and Data Validation using BigGridDemo. 


-----Original Message-----
From: Nick Burch [mailto:nick.burch@alfresco.com] 
Sent: Monday, March 14, 2011 6:15 PM
To: POI Users List
Subject: RE: Support for HSSF(.xls) in BigGridDemo

On Mon, 14 Mar 2011, Mamatha Kodigehalli Venkatesh wrote:
> I was able to use BigGridDemo for creating .xlsx using XSSF
>
> I want HSSF support to get the sheet Ref as the HSSFSheet does not have 
> the support of sheet.getPackagePart().getPartName().getName();

BigGridDemo is XSSF only. If you want to write code that works for both 
XSSF and HSSF, then you need to use the high level usermodel code.

Also, HSSF doesn't support streaming writing - there are just too many 
links forwards and backwards in the file

Nick

---------------------------------------------------------------------
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


RE: Support for HSSF(.xls) in BigGridDemo

Posted by Nick Burch <ni...@alfresco.com>.
On Mon, 14 Mar 2011, Mamatha Kodigehalli Venkatesh wrote:
> I was able to use BigGridDemo for creating .xlsx using XSSF
>
> I want HSSF support to get the sheet Ref as the HSSFSheet does not have 
> the support of sheet.getPackagePart().getPartName().getName();

BigGridDemo is XSSF only. If you want to write code that works for both 
XSSF and HSSF, then you need to use the high level usermodel code.

Also, HSSF doesn't support streaming writing - there are just too many 
links forwards and backwards in the file

Nick

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


RE: Support for HSSF(.xls) in BigGridDemo

Posted by Mamatha Kodigehalli Venkatesh <Ma...@ness.com>.
Any Comments/suggestion for my question below.

-----Original Message-----
From: Mamatha Kodigehalli Venkatesh [mailto:Mamatha.Venkatesh@ness.com] 
Sent: Friday, March 04, 2011 2:45 PM
To: POI Users List
Subject: Support for HSSF(.xls) in BigGridDemo


Hello,


I was able to use BigGridDemo for creating .xlsx using XSSF

I want HSSF support to get the sheet Ref as the HSSFSheet does not have the support of sheet.getPackagePart().getPartName().getName();

XSSFSheet sheet = wb.createSheet("Repository");
String sheetRef = sheet.getPackagePart().getPartName().getName();

Please suggest me, My requirement is to generate huge files (.xls & .xlsx).


Thanks in advance.

-mamatha

---------------------------------------------------------------------
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


Support for HSSF(.xls) in BigGridDemo

Posted by Mamatha Kodigehalli Venkatesh <Ma...@ness.com>.
Hello,


I was able to use BigGridDemo for creating .xlsx using XSSF

I want HSSF support to get the sheet Ref as the HSSFSheet does not have the support of sheet.getPackagePart().getPartName().getName();

XSSFSheet sheet = wb.createSheet("Repository");
String sheetRef = sheet.getPackagePart().getPartName().getName();

Please suggest me, My requirement is to generate huge files (.xls & .xlsx).


Thanks in advance.

-mamatha

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


Re: HSSF: HSSFSheet.setColumnWidth() has no effect

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
That's quite a common 'problem' really because, as I guess you know, setting
the width of a column using Excel you would enter a fugure like 20 or 50 and
5000 can seem a bit huge.

All the best with the project and if you hit any other problems, just drop a
message onto the list. The user list is the best place to ask questions like
"how do I set the background colour of a cell to red?" whilst the dev list
tends to be used to log bugs and enhancement requests. Not hard and fast
rules by any means but the user list tends to see more traffic, not all
users of the api visit both lists - even though the developers of the api do
- and, therefore, your question stands a better chance of being seen quickly
and answered promptly.

Yours

Mark B

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/HSSF-HSSFSheet-setColumnWidth-has-no-effect-tp2290119p3409286.html
Sent from the POI - User mailing list archive at Nabble.com.

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


Re: HSSF: HSSFSheet.setColumnWidth() has no effect

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
Firstly, please do not start - I know you started one and then posted on an
older thrtead with the same topic - more than one thread on a specific
problem as it can be confusing if different people respond to different
threads. Have you tried running just the code snippet I posted? That does
work and should test out the library for you.

Yours

Mark B

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/HSSF-HSSFSheet-setColumnWidth-has-no-effect-tp2290119p3409063.html
Sent from the POI - User mailing list archive at Nabble.com.

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