3 Replies - 188 Views - Last Post: 12 September 2012 - 01:32 PM Rate Topic: -----

#1 centerline  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 51
  • Joined: 17-October 10

Excel cells

Posted 12 September 2012 - 01:08 PM

never worked with Jxl or poi.hssf before, and not sure how to go about passing value(s) of a input file, parsing it (which I have already completed, and then passing EACH value into a/single cell. I am using a "FileInputStream" for the .xls file,passing that to a "new" HSSFWorkbook, to a HSSFSheet...ect. and all works file. But I am confused on how to pass the values parsed to the cell(s). Idealy, I want to be able to print console (just to see it) each header, then each individual cell.

HSSFCell cellA1 = row1.createCell(0);
...
cellA1.setCellValue("this works hardcoded");
//but looking for such:
cellA1.setCellValue(cellValue1);
//
cellA1.setCellValue(i); //for loop, or for each



Any "catch" or something special you have to do to get a value from say a parsing method?
I get a "The method setCellValue(double) in the type HSSFCell is not applicable for the arguments (void)" Red Line Error (Eclipse) when I try this.
I am guessing you have to return a value, but return a "single" value, if that indeed is what could be done, is where I am a litte lost.

Ideas? (not asking for code necessarily, just an approach to go about this.
Thanks to all! :)

Is This A Good Question/Topic? 0
  • +

Replies To: Excel cells

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8020
  • View blog
  • Posts: 31,127
  • Joined: 06-March 08

Re: Excel cells

Posted 12 September 2012 - 01:14 PM

View Postcenterline, on 12 September 2012 - 04:08 PM, said:

I am using a "FileInputStream" for the .xls file,passing that to a "new" HSSFWorkbook,

Why do you need a third party library if you read yourself the .xls ?
Was This Post Helpful? 0
  • +
  • -

#3 centerline  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 51
  • Joined: 17-October 10

Re: Excel cells

Posted 12 September 2012 - 01:25 PM

pbl, again, new to using Excel and Java. when trying to use "cell, rows, column..ect" I have researched (and tried going around these libraries with little luck):

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;



3rd party libraries for trying to do things as in:

Iterator rows = sheet.rowIterator();
  while (rows.hasNext()) {
    HSSFRow row = (HSSFRow) rows.next();
    Iterator cells = row.cellIterator();
    List<HSSFCell> data = new ArrayList<HSSFCell>();
      while (cells.hasNext()) {
	HSSFCell cell = (HSSFCell) cells.next();
        data.add(cell);
}
sheetData.add(data);



But not sure how to pass single values into single cells. (3rd party libraries or not)
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8020
  • View blog
  • Posts: 31,127
  • Joined: 06-March 08

Re: Excel cells

Posted 12 September 2012 - 01:32 PM

Don't know about your API but if you use JExelapi:

When you create a new Workbook obhject by reading and existing .XLS file or creating a new one you pass the FILE object to the API. It is not you (your code) that actually read/write the file. The handle of the file using FileInputStream/FileOutputSTream or whatever is done by the API. How can you read the .XLS file yourself if you know nothing (and catually you don't want to have to know anything) about its format.

http://jexcelapi.sou...l/Workbook.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1