You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Chris Barlock <ba...@us.ibm.com> on 2006/12/24 21:08:59 UTC

Import into Access Fails

I have the following test program that generates an XLS file with two 
columns.  If I try to import this XLS into Microsoft Access 2003 (File > 
Get External Data > Import) only the first column shows in the Access 
dialog listing the data to be imported.  If I change the XLS to have three 
columns, all three show up!  Is this a bug in my program, or a bug in the 
HSSF classes?

import java.io.FileOutputStream;

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;

public class Test2 {
    public static void main(String[] args) throws Exception {
        final String[] header = { 
            "a",
            "b",
            //"b", "c"
        };
 
        HSSFWorkbook wb = new HSSFWorkbook();
        HSSFSheet sheet = wb.createSheet("Sheet 1");
        HSSFRow row;
        HSSFCell cell; 
        HSSFWorkbook hssfwb = new HSSFWorkbook();

        // Write the header.
        row = sheet.createRow(0);
        for (short j = 0; j < header.length; j++) {
            row.createCell(j).setCellValue(header[j]);
        }

        // Write a row of data.
        short k = 0;
        row = sheet.createRow(1);
        cell = row.createCell(k++);
        cell.setCellValue("a_value");
        cell = row.createCell(k++);
        cell.setCellValue("b_value");
        //cell = row.createCell(k++);
        //cell.setCellValue("c_value");
 
        String outputFileName = "test.xls";
        FileOutputStream fos = new FileOutputStream(outputFileName);
        wb.write(fos);
        fos.close();
    }
}

Chris

IBM Tivoli Systems
Research Triangle Park, NC
(919) 224-2240
Internet:  barlock@us.ibm.com