Comment puis-je lire le file Excel en Java au format XML comme ci-dessous?
Si j'essaie
HSSFWorkbook wb = new HSSFWorkbook(ExcelFileToRead);
alors je reçois:
Exception in thread "main" java.io.IOException: Invalid header signature; read 0x726576206C6D783C, expected 0xE11AB1A1E011CFD0
Si j'essaie
XSSFWorkbook wb = new XSSFWorkbook(ExcelFileToRead);
alors je reçois:
Exception in thread "main" org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
Fichier Excel:
<xml version> <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas- microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"> <Styles> <Style ss:ID="Default" ss:Name="Normal"> <Alignment ss:Vertical="Bottom"/> <Borders/> <Font/> <Interior/> <NumberFormat/> <Protection/> </Style> <Style ss:ID="BoldColumn"> <Font x:Family="Swiss" ss:Bold="1"/> </Style> <Style ss:ID="SsortingngLiteral"> <NumberFormat ss:Format="@"/> </Style> <Style ss:ID="Decimal"> <NumberFormat ss:Format="0.0000"/> </Style> <Style ss:ID="Integer"> <NumberFormat ss:Format="0"/> </Style> <Style ss:ID="DateLiteral"> <NumberFormat ss:Format="mm/dd/yyyy;@"/> </Style>
Un grand merci pour toute aide. Mik
XSSF s'attend à un file ZIP réel avec les composants. L'erreur concerne le fait que le format OPC requirejs un file [Content_Types].xml
.
Une solution est de prendre un file XLSX existant, de le décompresser, de replace le file xl/worksheets/sheet1.xml
, puis de le xl/worksheets/sheet1.xml
.