[英]How to read embedded XLS file from URL
我必須從URL讀取一個excel文件並獲取其數據。 文件的名稱是companies.xls,但是當我用記事本打開此文件時,我發現它的文件類似於xls嵌入到HTML中。 Microsoft Excel可以毫無問題地打開該文件,並且我可以使用xls擴展名保存該文件,但是我必須以編程方式進行操作,或者必須找到其他任何方式來讀取此文件。 如何讀取此文件的數據? 由於不是純xslt,Apache poi文件系統給出以下錯誤;
java.io.IOException: Invalid header signature; read 0x6D78206C6D74683C, expected 0xE11AB1A1E011CFD0
這是我的代碼;
URL companyList= new URL("someURL.xslt");
InputStream inputStream = companyList.openStream();
POIFSFileSystem fs = new POIFSFileSystem(inputStream);
xls文件或html;
<head>
<meta http-equiv=Content-Type content="text/html; charset=Windows-1254">
<meta name=sssId content=Excel.Sheet>
<style type="text/css">
body,table,tr,th,td {font-family:Arial;font-size:11pt;color:#000;}
.th {padding:3em;background:#3366FF;text-align:center;color:#ffffff;}
.td {padding:2em;background:#ffffff;}
</style>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Companies</x:Name>
<x:WorksheetOptions>
<x:DefaultRowHeight>285</x:DefaultRowHeight>
<x:FreezePanes/>
<x:FrozenNoSplit/>
<x:SplitHorizontal>1</x:SplitHorizontal>
<x:TopRowBottomPane>1</x:TopRowBottomPane>
<x:ActivePane>2</x:ActivePane>
<x:Panes>
<x:Pane>
<x:Number>3</x:Number>
</x:Pane>
<x:Pane>
<x:Number>2</x:Number>
</x:Pane>
</x:Panes>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml><![endif]-->
</head>
<body>
<table width="100%" border="1">
<tr><th width="85%" class="th">Company Nameı</th><th width="15%" class="th">City</th></tr>
<tr><td width="100%" class="td">Microsoft</td><td width="100" align="center" class="td" nowrap>sValley</td> </tr>
<tr><td width="100%" class="td">Google</td><td width="100" align="center" class="td" nowrap>london</td></tr>
....
我遇到過同樣的問題。 此問題的解決方法是將該xls文件中的charset=Windows-1254
更改為charset=utf-8
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.