Bug 26573 - Set Cell Formula throws an error
Summary: Set Cell Formula throws an error
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-01 05:34 UTC by Rajesh S Krishnaiah
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rajesh S Krishnaiah 2004-02-01 05:34:07 UTC
If the formula contains a space or _ (underscore) charcters, setCellFormula 
throws array out of bounds exception.

Sample code:

import java.io.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.*;

public class FormulaError
{
  public static void main(String args[])
  {
    try
    {
      // New workbook
      FileOutputStream out = new FileOutputStream
("D://java//programs//test.xls");
      HSSFWorkbook book = new HSSFWorkbook();
      HSSFSheet sheet1 = book.createSheet("Test Sheet1"); // Note the space in 
between
      HSSFSheet sheet2 = book.createSheet("Sheet2");

      HSSFRow row = sheet1.createRow((short)0);
      HSSFCell cell = row.createCell((short)0);
      cell.setCellValue("SVUG1000");

      HSSFRow row2 = sheet2.createRow((short)0);
      HSSFCell cell2 = row2.createCell((short)0);
      // The space in the sheet name causes the set formula to throw an 
exception
      cell2.setCellFormula("Test Sheet1!A1"); // Link to cell 0 on sheet 1

      book.write(out);
      out.close();

    }
    catch (Exception ex)
    {
      System.out.println("Ex: " + ex);
    }
  }
}
Comment 1 Conrad Roche 2004-05-03 22:36:31 UTC
Change the line
    cell2.setCellFormula("Test Sheet1!A1"); 
to
    cell2.setCellFormula("'Test Sheet1'!A1"); 

and it should work.

cheers
Conrad