poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 26321] New: - After writing to XSL Workbook, cells have #NAME? values
Date Wed, 21 Jan 2004 19:19:59 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26321>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26321

After writing to XSL Workbook, cells have #NAME? values

           Summary: After writing to XSL Workbook, cells have #NAME? values
           Product: POI
           Version: 2.0-pre3
          Platform: PC
        OS/Version: Other
            Status: NEW
          Severity: Major
          Priority: Other
         Component: HSSF
        AssignedTo: poi-dev@jakarta.apache.org
        ReportedBy: jmnguyen@mail.arc.nasa.gov


Hi,
 I am working on a workbook with Macros in it. I'm not sure if this is the 
problem. I am currently on Windows 2000, using Excel 2000. When I execute my 
code, I get "Unknown PTG" warnings, but I am not modifying or inserting any 
Formulas at all. The formula cells are left alone. When I open the workbook, I 
get a "File Error: Data may have been lost" message. Some of the cells have 
#NAME? values in them, and if I re-save the file, almost every cell that had 
values changes to either #NAME? or #REF!, and sometimes it would not allow me 
to save the file at all ("File not saved"). I don't know what I am doing wrong, 
any help is greatly appreciated! Below is the code the causes this problem: 

    //this method writes to the xsl workbook -- Gets File error when opening and
    //re-saving
    private void set_intros_values()
    {
        FileInputStream fin = null;
        FileOutputStream fout = null;
        POIFSFileSystem poifs;
        HSSFWorkbook wb;
        HSSFName hssfname;
        HSSFSheet hssfsheet;
        HSSFCell cell;
        int index = 0, i = 0;
        int rownum = 0, colnum = 0;
        String name, cell_ref = null, sheet_name = null;
        StringTokenizer st, prev_str;
        Object new_val;
        double prev;
        try {
            fin = new FileInputStream(intros_filename);
            poifs = new POIFSFileSystem(fin);
            wb = new HSSFWorkbook(poifs);

            //go through the names and see if any of the named ranges
            for (Enumeration e = name_to_vals.keys(); e.hasMoreElements();)
            {
                name = (String)e.nextElement();
                index = wb.getNameIndex(name);
                hssfname = wb.getNameAt(index);
                cell_ref = hssfname.getReference();

                    //format -- sheet_name!$col$row
                    st = new StringTokenizer(cell_ref, "$ ");
                    st.nextToken();
                    //get cell column and row
                    colnum = get_col(st.nextToken().toLowerCase());
                    rownum = Integer.valueOf(st.nextToken()).intValue() - 1;

                    //the cell to write new value to
                    hssfsheet = wb.getSheet(hssfname.getSheetName());
                    cell = (HSSFCell)(hssfsheet.getRow((short)rownum).getCell
((short)colnum));

                    new_val = name_to_vals.get(name);
                    int cell_type = cell.getCellType();
                    //check for cell type
                    switch(cell_type){
                        //Double
                        case HSSFCell.CELL_TYPE_NUMERIC:
                            cell.setCellValue(((Double)new_val).doubleValue());
                            break;

                        //Formula -- *** DO NOTHING IF FORMULA !! *****
                        case HSSFCell.CELL_TYPE_FORMULA:
                            break;
                        default:
                            break;
                    }
                }
            }
            //write out results to intros workbook
            fout = new FileOutputStream(intros_filename);
            wb.write(fout);
            fout.close();
            fin.close();
        }
        catch (Exception exc){
            exc.printStackTrace();
        }
    }

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


Mime
View raw message