poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Christian_Eche...@mra.man.de>
Subject Import into Access Fails
Date Mon, 18 Jun 2007 11:14:15 GMT
I have the following test program that generates one XLS-Sheet with two
columns and one with three columns. If I try to import this XLS into
Microsoft Access 2003 (File > Get External Data > Import) for the sheet
with the even count of column only the first column is shown in the
Access dialog listing the data to be imported. For the sheet with the
odd count of columns all three columns are shown.

Is this bug in my program, in poi or in the import of access?
If i open and save the generated XLS with Excel, i do not have a problem
to import the file in access.
It seems POI writes an XLS that can not correctly be imported from
Access.


import java.io.File;
import java.io.FileOutputStream;

import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;


public class Main
{
    /**
     * @param args
     */
    public static void main(String[] args)
    {
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet;
        HSSFRow row;
        
        
        sheet = workbook.createSheet("test_even");
        row = sheet.createRow(0);
        row.createCell((short)0).setCellValue(new
HSSFRichTextString("rc=00"));
        row.createCell((short)1).setCellValue(new
HSSFRichTextString("rc=01"));
        row = sheet.createRow(1);
        row.createCell((short)0).setCellValue(new
HSSFRichTextString("rc=10"));
        row.createCell((short)1).setCellValue(new
HSSFRichTextString("rc=11"));
        
        
        sheet = workbook.createSheet("test_odd");
        row = sheet.createRow(0);
        row.createCell((short)0).setCellValue(new
HSSFRichTextString("rc=00"));
        row.createCell((short)1).setCellValue(new
HSSFRichTextString("rc=01"));
        row.createCell((short)2).setCellValue(new
HSSFRichTextString("rc=02"));
        row = sheet.createRow(1);
        row.createCell((short)0).setCellValue(new
HSSFRichTextString("rc=10"));
        row.createCell((short)1).setCellValue(new
HSSFRichTextString("rc=11"));
        row.createCell((short)2).setCellValue(new
HSSFRichTextString("rc=12"));
        
        FileOutputStream os;
        try {
            os = new FileOutputStream(new File("C:/temp/test.xls"));
            workbook.write(os);
            os.close();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Regards
Christian

Christian Echerer
Abt.: RAEM
Dipl.-Inf.(FH) 

MAN Roland Druckmaschinen AG
Vorsitzender des Aufsichtsrates: Hanno C. Fiedler
Vorstand: Gerd Finkbeiner (Vorsitzender), Dr. Ingo Koch, Dr. Markus Rall, Paul Steidle   

Sitz der Gesellschaft: Offenbach am Main, Registergericht: Amtsgericht Offenbach HRB-Nr. 42592
   
USt-Ident-Nr. DE 250200933

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


Mime
View raw message