You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by chewy4 <ch...@gmail.com> on 2011/07/19 21:10:09 UTC

HSSF Autosize Column Producing Huge 1st Column (POI 3.1)

Hi,

I'm currently using apache 3.1 and I have made a java program that lets you
enter any query into a form and gives you a spreadsheet back.

I'd like to make it resize all of the columns after it is done making the
spreadsheet, but when I do this it makes the first column gigantic and
doesn't resize the other ones correctly either.

Here is the code for the printing and resizing:

HSSFRow headerRow = sheet.createRow(1);
			//gathers header data and writes to workbook
			for (int i=0; i&lt;numberOfColumns; i++)
			{
				String header = rsMetaData.getColumnName(i+1);
				HSSFCell cell = headerRow.createCell((short)i);
				cell.setCellValue(header);
			
			}
			
			while (rs.next()) 
			{
				
				HSSFRow row =sheet.createRow((short)rs.getRow()+2);
				//gathers row results and writes to workbook
				for (int j=0; j&lt;numberOfColumns; j++)
				{
					String st = rs.getString(j+1);
					HSSFCell cell =row.createCell((short)j);
					cell.setCellValue(st);
				
				}
				
			}
			rs.close();
		
			//resizes columns 
			for (int k=0; k&lt;numberOfColumns; k++)
			{
				sheet.autoSizeColumn((short)k);
			}
			
	

&lt;/raw&gt;


Manually resizing isn't really an option as it is meant to take any query. I
have also tried putting the autosize logic right after the headers are made
and I get the same results. 

Any help is appreciated. 


--
View this message in context: http://apache-poi.1045710.n5.nabble.com/HSSF-Autosize-Column-Producing-Huge-1st-Column-POI-3-1-tp4613320p4613320.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: InvalidOperation retrieving InputStream

Posted by "Pruitt, Byron S" <st...@hp.com>.
Yes, of course.  This is a classic example of assuming the problem is harder than it really is.  The PackageProperties works for what I need.

Thanks.



-----Original Message-----
From: Nick Burch [mailto:nick.burch@alfresco.com] 
Sent: Thursday, July 21, 2011 9:26 AM
To: POI Users List
Subject: RE: InvalidOperation retrieving InputStream

On Thu, 21 Jul 2011, Pruitt, Byron S wrote:
> I simply need to extract it for read only purposes.

You have two choices. One is to use the methods provided by POI to read 
and manipulate the core properties part - PackagePropertiesPart

The other, if you don't want any of the checking or validation or helpers,
is simply just to open the file as a regular .zip and read the core part 
from that

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: InvalidOperation retrieving InputStream

Posted by Nick Burch <ni...@alfresco.com>.
On Thu, 21 Jul 2011, Pruitt, Byron S wrote:
> I simply need to extract it for read only purposes.

You have two choices. One is to use the methods provided by POI to read 
and manipulate the core properties part - PackagePropertiesPart

The other, if you don't want any of the checking or validation or helpers,
is simply just to open the file as a regular .zip and read the core part 
from that

Nick

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


RE: InvalidOperation retrieving InputStream

Posted by "Pruitt, Byron S" <st...@hp.com>.
I simply need to extract it for read only purposes.



-----Original Message-----
From: Nick Burch [mailto:nick.burch@alfresco.com] 
Sent: Wednesday, July 20, 2011 6:42 PM
To: POI Users List
Subject: Re: InvalidOperation retrieving InputStream

On Wed, 20 Jul 2011, Pruitt, Byron S wrote:
> I am having a problem with the openxml4j library in poi 3.7.
>
> OPCPackage pkg = OPCPackage.open(filePath);
> PackagePartName corePartName = PackagingURIHelper.createPartName("/docProps/core.xml");
> PackagePart dCore = pkg.getPart(corePartName);
>
> System.out.println(dCore.getContentType());
> System.out.println(dCore.getPartName().getName());
>
> InputStream strmCore = dCore.getInputStream();

I think you're not supposed to work with the core part in this way. It's a 
special part with certain restrictions, which POI enforces

What were you hoping to do with the core part? (There may well be a better 
way to do it)

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: InvalidOperation retrieving InputStream

Posted by Nick Burch <ni...@alfresco.com>.
On Wed, 20 Jul 2011, Pruitt, Byron S wrote:
> I am having a problem with the openxml4j library in poi 3.7.
>
> OPCPackage pkg = OPCPackage.open(filePath);
> PackagePartName corePartName = PackagingURIHelper.createPartName("/docProps/core.xml");
> PackagePart dCore = pkg.getPart(corePartName);
>
> System.out.println(dCore.getContentType());
> System.out.println(dCore.getPartName().getName());
>
> InputStream strmCore = dCore.getInputStream();

I think you're not supposed to work with the core part in this way. It's a 
special part with certain restrictions, which POI enforces

What were you hoping to do with the core part? (There may well be a better 
way to do it)

Nick

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


InvalidOperation retrieving InputStream

Posted by "Pruitt, Byron S" <st...@hp.com>.
I am having a problem with the openxml4j library in poi 3.7.

OPCPackage pkg = OPCPackage.open(filePath);
PackagePartName corePartName = PackagingURIHelper.createPartName("/docProps/core.xml");
PackagePart dCore = pkg.getPart(corePartName);

System.out.println(dCore.getContentType());
System.out.println(dCore.getPartName().getName());

InputStream strmCore = dCore.getInputStream();

The above code produces this exception:

org.apache.poi.openxml4j.exceptions.InvalidOperationException: Operation not authorized
	at org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart.getInputStreamImpl(PackagePropertiesPart.java:599)
	at org.apache.poi.openxml4j.opc.PackagePart.getInputStream(PackagePart.java:466)
	at com.test.DocTest.main(DocTest.java:42)

Line 42 is the getInputStream call.  The two sys outs show the expected values.  I must be missing something very obvious.

Thanks for any help.


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


Re: HSSF Autosize Column Producing Huge 1st Column (POI 3.1)

Posted by chewy4 <ch...@gmail.com>.
I have no idea, not sure where I would check that. I didn't set up the server
and really don't know all that much about it, I just mostly fix various web
apps on it. All I know is that it's an oracle 10g(10.2.02) server with Java
1.4.2 . I'm not using any special fonts though, just the defaults.

Some columns in some tables is does work on though which is weird. For
example I have a query that returns ID, NAME, and DATEMODIFIED which usually
returns correct resizing(occasionaly the first column is big). But on a
query that returns NAMEID, PHONENUMBER, TYPE, DATEMODIFIEDNUM, and NUMBERID
only DATEMODIFIEDNUM is ever correctly re-sized while TYPE and NUMBERID are
consistently re-sized too small, and NAMEID is either huge or cut off short.




--
View this message in context: http://apache-poi.1045710.n5.nabble.com/HSSF-Autosize-Column-Producing-Huge-1st-Column-POI-3-1-tp4613320p4615986.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 Autosize Column Producing Huge 1st Column (POI 3.1)

Posted by Nick Burch <ni...@alfresco.com>.
On Wed, 20 Jul 2011, chewy4 wrote:
> And I just got done putting 3.2 on the server and the problem still 
> seems to be there in a way. Kind of weird, it returns a different format 
> every time. Sometimes the first 1-3 columns are big, sometimes it's 
> almost resized correctly except for a couple columns.

Quick check - do you have all the required fonts on your server? We need 
the font to be able to work out how big the characters are, and if the 
ideal font isn't there then we'll fall back to the "nearest" one which may 
not be close enough...

Nick

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


Re: HSSF Autosize Column Producing Huge 1st Column (POI 3.1)

Posted by chewy4 <ch...@gmail.com>.
And I just got done putting 3.2 on the server and the problem still seems to
be there in a way. Kind of weird, it returns a different format every time.
Sometimes the first 1-3 columns are big, sometimes it's almost resized
correctly except for a couple columns.

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/HSSF-Autosize-Column-Producing-Huge-1st-Column-POI-3-1-tp4613320p4615851.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 Autosize Column Producing Huge 1st Column (POI 3.1)

Posted by chewy4 <ch...@gmail.com>.
Hm not sure why I thought 3.1 was the latest for 1.4...

I tested it with 3.2 though and it seemed to work locally. Then I tested it
with 3.1 locally and that seemed to work too.

It looks like the problem is only in the part that runs on the server. The
difference between the class that the server uses and the main one is that
it saves the spreadsheet differently since it returns a blob.


This is the code I use to write it to a blob,xls_blob being the empty blob
that is being passed in as a parameter:

OutputStream os = xls_blob.getBinaryOutputStream();
wb.write(os);
os.close();

Is there anything wrong with that or is there something about writing to a
blob that makes things like this get lost in translation? I'm not too
familiar with blobs myself.

I'm going to try to get 3.2 on the server and see if that fixes anything, if
it doesn't it's probably a good idea to have it anyways.


--
View this message in context: http://apache-poi.1045710.n5.nabble.com/HSSF-Autosize-Column-Producing-Huge-1st-Column-POI-3-1-tp4613320p4615747.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 Autosize Column Producing Huge 1st Column (POI 3.1)

Posted by Nick Burch <ni...@alfresco.com>.
On Wed, 20 Jul 2011, chewy4 wrote:
> The server I'm running this on only has Java 1.4.2 so I can't run any later
> versions.

You should be able to use POI 3.2 then, that was our last 1.4 release

> Am I pretty much out of luck if I'm unable to use a more recent version?

Try it on your dev box with 3.8 beta 3. If that fixes it, you'll be 
looking at the "fun" of backporting the appropriate resize code...

Nick

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


Re: HSSF Autosize Column Producing Huge 1st Column (POI 3.1)

Posted by chewy4 <ch...@gmail.com>.
The server I'm running this on only has Java 1.4.2 so I can't run any later
versions.

Am I pretty much out of luck if I'm unable to use a more recent version?

--
View this message in context: http://apache-poi.1045710.n5.nabble.com/HSSF-Autosize-Column-Producing-Huge-1st-Column-POI-3-1-tp4613320p4615621.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 Autosize Column Producing Huge 1st Column (POI 3.1)

Posted by Nick Burch <ni...@alfresco.com>.
On Tue, 19 Jul 2011, chewy4 wrote:
> I'm currently using apache 3.1 and I have made a java program that lets 
> you enter any query into a form and gives you a spreadsheet back.

POI 3.1 is over 3 years old now, I'd strongly suggest you retry with a 
newer version (ideally 3.8 beta 3, or failing that 3.7) and there's a fair 
chance your issue will have been solved in the mean time

Nick

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