Editing specific (existing) excel cells
i am trying to send information entered from the user in a java application into existing cells in a worksheet. I have the jxl package, and have not tried api. Can anyone provide a solution?
current code:
private static File file = new File("AutoInvoice.xlsx");
public InvoiceModifier()
{
}
public static void editInvoice(String address)
{
try
{
FileInputStream fis=new FileInputStream(file);
Workbook workbook = Workbook.getWorkbook(fis);
WritableWorkbook copy = Workbook.createWorkbook(new File("newinvoice.xlsx"), workbook);
WritableSheet sheet = copy.getSheet(0);
WritableCell cell = sheet.getWritableCell(6,0);
if (cell.getType() == CellType.LABEL)
{
Label l = (Label)cell;
l.setValue(address);
}
// All cells modified/added. Now write out the workbook
copy.write();
copy.close();
workbook.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
Re: Editing specific (existing) excel cells
Forum Rules
http://www.java-forums.org/forum-gui...w-members.html
BB Code List - Java Programming Forum
You didn't bother to reply to mcajavaprogramer's response in your earlier thread. Why should we expect any better behavior this time round?
db
Re: Editing specific (existing) excel cells
Quote:
Originally Posted by
bolbi123456
I have the jxl package, and have not tried api. Can anyone provide a solution?
First you need to tell us why you have 'not tried API'
db
Re: Editing specific (existing) excel cells
What happens when you use the code above?
Re: Editing specific (existing) excel cells
a write exception is thrown, because the data type can not be specified. i have checked all of the data types in the excel spreadsheet and it matches,
the part that skips while debugging is
if (cell.getType() == CellType.LABEL)
Re: Editing specific (existing) excel cells
-darryl, i have searched and just wanted to know if it was possible to edit cells with jxl.
thanks
Re: Editing specific (existing) excel cells
Post the full exception plus stack trace and highlight the line it occurs on.
Re: Editing specific (existing) excel cells
managed to get the one exception fixed, however i get a new error message that i can find no solutions to online.
while reading the if statement, the error show is
"Warning: Text on sheet "Simple with Sales Tax" not supported - omitting"
iv noticed a few others with the same problem but there have been no replies on related threads. thanks to anyone with an answer
Re: Editing specific (existing) excel cells
What does the code look like now (and please use [code] tags [/code])?
Also give us the full error/warning including any stack trace associated with it.
Re: Editing specific (existing) excel cells
managed to get the one exception fixed, however i get a new error message that i can find no solutions to online.
while reading the if statement, the error shown is
"Warning: Text on sheet "Simple with Sales Tax" not supported - omitting"
it is the only thing written with printstacktrace
iv noticed a few others with the same problem but there have been no replies on related threads. thanks to anyone with an answer
Re: Editing specific (existing) excel cells
Repeating your earlier post and not replying to the question posed by Tolls isn't going to help you get help.
db
Re: Editing specific (existing) excel cells
the code is the same as earlier posted.. the only thing changed is the file extension, changed from "xlsx" to "xlt".
the only error shown in the terminal is
"Warning: Text on sheet "Simple with Sales Tax" not supported - omitting"
Re: Editing specific (existing) excel cells
'xlt'?
I assume you mean 'xls'.
Not knowing what your Excel sheet looks like I can only guess that there is something on it that JExcel does not support.
I would start by paring the sheet down to a basic sheet with cells and data and the start adding in the fancier bits (including any formula cells). You should eventually find the thing that it's complaining about.
Re: Editing specific (existing) excel cells
XLT is the extension for an Excel template.
db
Re: Editing specific (existing) excel cells
Oh right.
Then I would check what limitations JExcel has around templates (and do the paring down above as well).
Assuming that warning is coming from JExcel (where else would it be coming from?) then it's pretty clear that there's something there it doesn't support.
Re: Editing specific (existing) excel cells
ok thanks alot everyone, ill try recreating the excel sheet myself and post the results.
Re: Editing specific (existing) excel cells
Another option is to try the same sort of thing with Apache POI.
Re: Editing specific (existing) excel cells
tried for hours to get it working with jxl, with no success. downloaded the apache poi jar file and followed a few online starters, i managed to get the sheet edited within about an hour.
lesson - when editing spreadsheets, use POI!
thanks everyone