You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Mauro Daniel Ardolino <ma...@altersoft.com.ar> on 2003/11/19 20:33:00 UTC

Reading-Writing, several sheets

Hello!

I'm having a problem when I try to read/write an excel workbook with 2
sheets.

In the A1 of the second sheet I have a formula (cross sheet one!).

The first sheet is empty.

The program must set "hello" in A1 of the first sheet.  And then save.

Environment:
- Linux RH73
- JSDK 1.4.1_02
- POI-VERSION: 1.10.0-dev-20030222

Here's the code...do you see anything wrong?

package ar.com.altersoft.msexcel.testing;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;


public class WritingAnExistingXlsTest {
	public static void main(String[] args) {
		try {
			FileInputStream fin = new FileInputStream("templateDemoTesting.xls");
			POIFSFileSystem poifs = new POIFSFileSystem(fin);
			HSSFWorkbook wb= new HSSFWorkbook(poifs);
			//
			HSSFSheet sheet=wb.getSheetAt(wb.getSheetIndex("page1"));
			//sheet.setSelected(true);
			HSSFRow row= sheet.getRow(0);
			if(row==null){
				row= sheet.createRow(0);
			}
			HSSFCell cell= row.getCell((short)0);
			if(cell==null){
				cell= row.createCell((short)0);
			}
			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
			cell.setCellValue("hello");
			//
			FileOutputStream fileOut = new FileOutputStream("templateDemoTestingResult.xls");
			wb.write(fileOut);
			fileOut.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();			
		}		
	}
	
}// END CLASS



Thanks in advance. Regards,

-- Mauro



-- 
Ing.Mauro Daniel Ardolino
Departamento de Desarrollo y Servicios
Altersoft
mailto: mauro@altersoft.com.ar
website: http://www.altersoft.com.ar

   .~.
   /v\ 
  // \\ "In Linux we trust"
 /(   )\ 
  ^^-^^



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


trapping error message - urgent

Posted by som kolli <so...@knacksystems.com>.
Hi all

Iam using POI for reading the excel sheet ..

I have to do null validations for the cells in my java code...

If I delete the content of a cell from the excel sheet, when POI tries to
read the cell using cell.getStringValue(); what does it return ; null or
""... how to put the condition for my validation.... pls help me out.

thanks
Som



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


Re: Reading-Writing, several sheets

Posted by Avik Sengupta <av...@itellix.com>.
Well, monologue's are good!

but, yeah, good you got your problems fixed, thanks for investigating
and letting us know!

On Thu, 2003-11-20 at 01:49, Mauro Daniel Ardolino wrote:
> It seem it's a monologue, but well, here's the answer:
> The problem was sure a bug.  I installed a new poi version and the problem
> was fixed.
> Now I'm using: poi-2.0-RC1-20031102.jar
> 
> -- Mauro
> 
> 
> On Wed, 19 Nov 2003, Mauro Daniel Ardolino wrote:
> 
> > Hey! I'm sorry! I didn't specify the problem:
> > Nothing appears in A1 of the first sheet of the resultant xls.
> > ;)
> > -- Mauro
> > 
> > On Wed, 19 Nov 2003, Mauro Daniel Ardolino wrote:
> > 
> > > Hello!
> > > 
> > > I'm having a problem when I try to read/write an excel workbook with 2
> > > sheets.
> > > 
> > > In the A1 of the second sheet I have a formula (cross sheet one!).
> > > 
> > > The first sheet is empty.
> > > 
> > > The program must set "hello" in A1 of the first sheet.  And then save.
> > > 
> > > Environment:
> > > - Linux RH73
> > > - JSDK 1.4.1_02
> > > - POI-VERSION: 1.10.0-dev-20030222
> > > 
> > > Here's the code...do you see anything wrong?
> > > 
> > > package ar.com.altersoft.msexcel.testing;
> > > 
> > > import java.io.File;
> > > import java.io.FileInputStream;
> > > import java.io.FileNotFoundException;
> > > import java.io.FileOutputStream;
> > > import java.io.IOException;
> > > 
> > > import org.apache.poi.hssf.usermodel.HSSFCell;
> > > import org.apache.poi.hssf.usermodel.HSSFRow;
> > > import org.apache.poi.hssf.usermodel.HSSFSheet;
> > > import org.apache.poi.hssf.usermodel.HSSFWorkbook;
> > > import org.apache.poi.poifs.filesystem.POIFSFileSystem;
> > > 
> > > 
> > > public class WritingAnExistingXlsTest {
> > > 	public static void main(String[] args) {
> > > 		try {
> > > 			FileInputStream fin = new FileInputStream("templateDemoTesting.xls");
> > > 			POIFSFileSystem poifs = new POIFSFileSystem(fin);
> > > 			HSSFWorkbook wb= new HSSFWorkbook(poifs);
> > > 			//
> > > 			HSSFSheet sheet=wb.getSheetAt(wb.getSheetIndex("page1"));
> > > 			//sheet.setSelected(true);
> > > 			HSSFRow row= sheet.getRow(0);
> > > 			if(row==null){
> > > 				row= sheet.createRow(0);
> > > 			}
> > > 			HSSFCell cell= row.getCell((short)0);
> > > 			if(cell==null){
> > > 				cell= row.createCell((short)0);
> > > 			}
> > > 			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
> > > 			cell.setCellValue("hello");
> > > 			//
> > > 			FileOutputStream fileOut = new FileOutputStream("templateDemoTestingResult.xls");
> > > 			wb.write(fileOut);
> > > 			fileOut.close();
> > > 		} catch (FileNotFoundException e) {
> > > 			e.printStackTrace();
> > > 		} catch (IOException e) {
> > > 			e.printStackTrace();			
> > > 		}		
> > > 	}
> > > 	
> > > }// END CLASS
> > > 
> > > 
> > > 
> > > Thanks in advance. Regards,
> > > 
> > > -- Mauro
> > > 
> > > 
> > > 
> > > 
> > 
> > 


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


Re: Reading-Writing, several sheets

Posted by Mauro Daniel Ardolino <ma...@altersoft.com.ar>.
It seem it's a monologue, but well, here's the answer:
The problem was sure a bug.  I installed a new poi version and the problem
was fixed.
Now I'm using: poi-2.0-RC1-20031102.jar

-- Mauro


On Wed, 19 Nov 2003, Mauro Daniel Ardolino wrote:

> Hey! I'm sorry! I didn't specify the problem:
> Nothing appears in A1 of the first sheet of the resultant xls.
> ;)
> -- Mauro
> 
> On Wed, 19 Nov 2003, Mauro Daniel Ardolino wrote:
> 
> > Hello!
> > 
> > I'm having a problem when I try to read/write an excel workbook with 2
> > sheets.
> > 
> > In the A1 of the second sheet I have a formula (cross sheet one!).
> > 
> > The first sheet is empty.
> > 
> > The program must set "hello" in A1 of the first sheet.  And then save.
> > 
> > Environment:
> > - Linux RH73
> > - JSDK 1.4.1_02
> > - POI-VERSION: 1.10.0-dev-20030222
> > 
> > Here's the code...do you see anything wrong?
> > 
> > package ar.com.altersoft.msexcel.testing;
> > 
> > import java.io.File;
> > import java.io.FileInputStream;
> > import java.io.FileNotFoundException;
> > import java.io.FileOutputStream;
> > import java.io.IOException;
> > 
> > import org.apache.poi.hssf.usermodel.HSSFCell;
> > import org.apache.poi.hssf.usermodel.HSSFRow;
> > import org.apache.poi.hssf.usermodel.HSSFSheet;
> > import org.apache.poi.hssf.usermodel.HSSFWorkbook;
> > import org.apache.poi.poifs.filesystem.POIFSFileSystem;
> > 
> > 
> > public class WritingAnExistingXlsTest {
> > 	public static void main(String[] args) {
> > 		try {
> > 			FileInputStream fin = new FileInputStream("templateDemoTesting.xls");
> > 			POIFSFileSystem poifs = new POIFSFileSystem(fin);
> > 			HSSFWorkbook wb= new HSSFWorkbook(poifs);
> > 			//
> > 			HSSFSheet sheet=wb.getSheetAt(wb.getSheetIndex("page1"));
> > 			//sheet.setSelected(true);
> > 			HSSFRow row= sheet.getRow(0);
> > 			if(row==null){
> > 				row= sheet.createRow(0);
> > 			}
> > 			HSSFCell cell= row.getCell((short)0);
> > 			if(cell==null){
> > 				cell= row.createCell((short)0);
> > 			}
> > 			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
> > 			cell.setCellValue("hello");
> > 			//
> > 			FileOutputStream fileOut = new FileOutputStream("templateDemoTestingResult.xls");
> > 			wb.write(fileOut);
> > 			fileOut.close();
> > 		} catch (FileNotFoundException e) {
> > 			e.printStackTrace();
> > 		} catch (IOException e) {
> > 			e.printStackTrace();			
> > 		}		
> > 	}
> > 	
> > }// END CLASS
> > 
> > 
> > 
> > Thanks in advance. Regards,
> > 
> > -- Mauro
> > 
> > 
> > 
> > 
> 
> 

-- 
Ing.Mauro Daniel Ardolino
Departamento de Desarrollo y Servicios
Altersoft
mailto: mauro@altersoft.com.ar
website: http://www.altersoft.com.ar

   .~.
   /v\ 
  // \\ "In Linux we trust"
 /(   )\ 
  ^^-^^


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


Re: Reading-Writing, several sheets

Posted by Mauro Daniel Ardolino <ma...@altersoft.com.ar>.
Hey! I'm sorry! I didn't specify the problem:
Nothing appears in A1 of the first sheet of the resultant xls.
;)
-- Mauro

On Wed, 19 Nov 2003, Mauro Daniel Ardolino wrote:

> Hello!
> 
> I'm having a problem when I try to read/write an excel workbook with 2
> sheets.
> 
> In the A1 of the second sheet I have a formula (cross sheet one!).
> 
> The first sheet is empty.
> 
> The program must set "hello" in A1 of the first sheet.  And then save.
> 
> Environment:
> - Linux RH73
> - JSDK 1.4.1_02
> - POI-VERSION: 1.10.0-dev-20030222
> 
> Here's the code...do you see anything wrong?
> 
> package ar.com.altersoft.msexcel.testing;
> 
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.FileNotFoundException;
> import java.io.FileOutputStream;
> import java.io.IOException;
> 
> import org.apache.poi.hssf.usermodel.HSSFCell;
> import org.apache.poi.hssf.usermodel.HSSFRow;
> import org.apache.poi.hssf.usermodel.HSSFSheet;
> import org.apache.poi.hssf.usermodel.HSSFWorkbook;
> import org.apache.poi.poifs.filesystem.POIFSFileSystem;
> 
> 
> public class WritingAnExistingXlsTest {
> 	public static void main(String[] args) {
> 		try {
> 			FileInputStream fin = new FileInputStream("templateDemoTesting.xls");
> 			POIFSFileSystem poifs = new POIFSFileSystem(fin);
> 			HSSFWorkbook wb= new HSSFWorkbook(poifs);
> 			//
> 			HSSFSheet sheet=wb.getSheetAt(wb.getSheetIndex("page1"));
> 			//sheet.setSelected(true);
> 			HSSFRow row= sheet.getRow(0);
> 			if(row==null){
> 				row= sheet.createRow(0);
> 			}
> 			HSSFCell cell= row.getCell((short)0);
> 			if(cell==null){
> 				cell= row.createCell((short)0);
> 			}
> 			cell.setCellType(HSSFCell.CELL_TYPE_STRING);
> 			cell.setCellValue("hello");
> 			//
> 			FileOutputStream fileOut = new FileOutputStream("templateDemoTestingResult.xls");
> 			wb.write(fileOut);
> 			fileOut.close();
> 		} catch (FileNotFoundException e) {
> 			e.printStackTrace();
> 		} catch (IOException e) {
> 			e.printStackTrace();			
> 		}		
> 	}
> 	
> }// END CLASS
> 
> 
> 
> Thanks in advance. Regards,
> 
> -- Mauro
> 
> 
> 
> 

-- 
Ing.Mauro Daniel Ardolino
Departamento de Desarrollo y Servicios
Altersoft
mailto: mauro@altersoft.com.ar
website: http://www.altersoft.com.ar

   .~.
   /v\ 
  // \\ "In Linux we trust"
 /(   )\ 
  ^^-^^


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