使用 Ole 连接访问 MS Excel XML 格式

发布于 2024-08-07 14:31:54 字数 5197 浏览 1 评论 0原文

如何使用 OLE 连接访问 XML Excel 格式文件?能做到吗?我已经访问了正常的 Excel Format 2003 xlsx 文件,但是当我生成 Excel XML 格式时,我无法使用 OLE 访问。预先感谢您的任何帮助。

我可以在 Excel 中手动打开该文件,但无法通过 OleDb 连接连接到它。我通过共享驱动器上的内存流将自己的 XML 转储到 Excel 文件中。如果我手动将 Excel 中的文件另存为 Excel 97-2003 格式。但是当我将其保存为 XML 文件时,我无法通过数据连接访问它。

我的连接看起来像这样......

String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
    "Data Source=" + file_path + ";Extended Properties=Excel 8.0;";

感谢您的高级帮助。

这是我保存到 xls 文件并在 Excel 中打开的代码,它工作正常。我从我的应用程序生成 XML。我正在尝试使用 Ole 访问同一文件?

<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40"
<head>
<style>
<!--table
@page
{margin:0.0in .0in 0.34in .0in;
mso-header-margin:.5in;
mso-footer-margin:.18in;
mso-footer-data:"Page &P of  &N";
mso-page-orientation:landscape;}
-->
</style>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Summary</x:Name>
<x:WorksheetOptions>
<x:FitToPage/>
<x:FitToPage/>
<x:Print>
<x:FitHeight>32767</x:FitHeight><x:ValidPrinterInfo/>
<x:HorizontalResolution>600</x:HorizontalResolution>
<x:VerticalResolution>600</x:VerticalResolution>
<x:DoNotDisplayGridlines/>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>

<Worksheet ss:Name="DATE1">
  <Table ss:ExpandedColumnCount="13" ss:ExpandedRowCount="2" x:FullColumns="1"
   x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="14.25">
   <Row ss:Height="63.75">
   <Cell ss:StyleID="s63"><Data ss:Type="String">DATE</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something1</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something2</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something3</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something4</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something5</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something6</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something7</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something8</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something9</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something10</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something11</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something12</Data></Cell>
  </Row>
  <Row>
   <Cell ss:StyleID="s65"><Data ss:Type="String">something</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">268763</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">1331476</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">48267</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">1283209</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">34589</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">0.97304492097546003</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">23921</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">10668</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">0.99168646728631105</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">1730</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">8938</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">99.303464985049203</Data></Cell>
  </Row>
 </Table>
 <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
  <FitToPage/>
   <Print>
   <FitHeight>32767</FitHeight>
   <ValidPrinterInfo/>
    <HorizontalResolution>600</HorizontalResolution>
   <VerticalResolution>600</VerticalResolution>
  </Print>
  <Selected/>
  <Panes>
   <Pane>
    <Number>3</Number>
     <RangeSelection>R1C1:R2C13</RangeSelection>
   </Pane>
  </Panes>
  <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
 </Worksheet>
</Workbook>

</xml><![endif]-->

</head>
</html>

How can I access a XML Excel format file with an OLE Connection? Can it be done? I have accessed the normal Excel Format 2003 xlsx file but when I generate the Excel XML format I can't access with OLE. Thanks in advance for any help.

I can open the file manually in Excel but I'm unable to connect to it through the OleDb Connection. I'm dumping my own XML in the Excel file through a memory stream on a shared drive. If I manually save a file from Excel as a Excel 97-2003 format. But when I save it as a XML file I can't access it through the dataconnection.

My connection looks like this....

String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
    "Data Source=" + file_path + ";Extended Properties=Excel 8.0;";

Thanks for the help in advanced.

This is the code that I save to an xls file and open in Excel it works fine. I generate the XML from my app. I'm trying to access the same file with Ole?

<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40"
<head>
<style>
<!--table
@page
{margin:0.0in .0in 0.34in .0in;
mso-header-margin:.5in;
mso-footer-margin:.18in;
mso-footer-data:"Page &P of  &N";
mso-page-orientation:landscape;}
-->
</style>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Summary</x:Name>
<x:WorksheetOptions>
<x:FitToPage/>
<x:FitToPage/>
<x:Print>
<x:FitHeight>32767</x:FitHeight><x:ValidPrinterInfo/>
<x:HorizontalResolution>600</x:HorizontalResolution>
<x:VerticalResolution>600</x:VerticalResolution>
<x:DoNotDisplayGridlines/>
<x:ProtectContents>False</x:ProtectContents>
<x:ProtectObjects>False</x:ProtectObjects>
<x:ProtectScenarios>False</x:ProtectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>

<Worksheet ss:Name="DATE1">
  <Table ss:ExpandedColumnCount="13" ss:ExpandedRowCount="2" x:FullColumns="1"
   x:FullRows="1" ss:DefaultColumnWidth="54" ss:DefaultRowHeight="14.25">
   <Row ss:Height="63.75">
   <Cell ss:StyleID="s63"><Data ss:Type="String">DATE</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something1</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something2</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something3</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something4</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something5</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something6</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something7</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something8</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something9</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something10</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something11</Data></Cell>
   <Cell ss:StyleID="s63"><Data ss:Type="String">something12</Data></Cell>
  </Row>
  <Row>
   <Cell ss:StyleID="s65"><Data ss:Type="String">something</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">268763</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">1331476</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">48267</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">1283209</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">34589</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">0.97304492097546003</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">23921</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">10668</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">0.99168646728631105</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">1730</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">8938</Data></Cell>
   <Cell ss:StyleID="s65"><Data ss:Type="Number">99.303464985049203</Data></Cell>
  </Row>
 </Table>
 <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
  <FitToPage/>
   <Print>
   <FitHeight>32767</FitHeight>
   <ValidPrinterInfo/>
    <HorizontalResolution>600</HorizontalResolution>
   <VerticalResolution>600</VerticalResolution>
  </Print>
  <Selected/>
  <Panes>
   <Pane>
    <Number>3</Number>
     <RangeSelection>R1C1:R2C13</RangeSelection>
   </Pane>
  </Panes>
  <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
 </Worksheet>
</Workbook>

</xml><![endif]-->

</head>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゝ偶尔ゞ 2024-08-14 14:31:54

从您更新的问题来看,您似乎正在使用 Excel 的 HTML 导出(它将某种 XML 嵌入到可能由 Internet Explorer 呈现的导出页面的 HTML 头部中。我认为这种格式可以追溯到 Excel 2000 并且不支持 。

出于遗留原因,您是否需要使用这种格式?现在有更好的选择,例如使用 Office 2007 的新的基于 XML 的 Office OpenXML 格式或 XML 电子表格 2003 Excel 2003 引入的格式。

From your updated question it seems as if you are using Excel's HTML export (which embeds some sort of XML into the HTML head of the exported page that might be rendered by Internet Explorer. I think this format dates back to Excel 2000 and does not support data binding.

Are you required to use such a format for legacy reasons? By now there are much better options, e.g. with the new XML-based Office OpenXML formats of Office 2007 or the XML Spreadsheet 2003 format introduced by Excel 2003.

南薇 2024-08-14 14:31:54

扩展属性=Excel 12.0 ?

Extended Properties=Excel 12.0 ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文