我被困在完成我的程序的最后一道障碍上。我有一个 excel 文档,我想导入到我用 C# 构建的文档中
wb.Sheets.Add();
Microsoft.Office.Interop.Excel.Worksheet staffCosts = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[1];
staffCosts.Name = "Staff Costs";
staffCosts.QueryTables[1].Name = Path.GetFileNameWithoutExtension("C:\\tilldataoutput\\excelcreator\\excelcreator\\bin\\Debug\\Staff.xlsx");
如有任何帮助,我们将不胜感激。
最佳答案
看看这个MSDN链接,其中说明...
Returns the QueryTables collection that represents all the query tables on the specified worksheet. Read-only.
由于您通过使用索引获得 QueryTable
,因此您应该首先检查集合以检查是否存在,或者在您的情况下检查 2,因为您正在查看第二个 查询表
。
关于c# - 将第二个电子表格导入 Microsoft.Office.Interop.Excel C# 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25059445/