Tag: c#

尝试使用Excel 2007执行Office自动化,但仍使用Excel 2003

环境: Windows XP机器 安装Excel 2007和Excel 2003(按顺序,不按时间顺序)。 C#3.5 问题: 当我使用PIA做一些Office自动化时,我使用下面的代码行: var excel = new ApplicationClass(); PIA的版本专门将其称为Excel 12。 C:\ Windows \组件\ GAC \的Microsoft.Office.Interop.Excel \ 12.0.0.0__71e9bce111e9429c \ Microsoft.Office.Interop.Excel.dll 但: excel.Version;//this is 11.0 instead of 12.0 因此,当我尝试打开扩展名为.xlsx的文件时,它会警告我在文件转换中丢失的function,并用excel 2003打开它。我非常肯定它与安装顺序是2007 – > 2003有关,但我不能卸载2003在我的机器上我们有一些办公自动化在我们的networking服务器上使用excel 2003的无关项目。 我已经看了Policy.11.0.Microsoft.Office.Interop.Excel.config的东西,但它说 <bindingRedirect oldVersion="11.0.0.0" newVersion="12.0.0.0"></bindingRedirect> 所以,我不知所措。 为什么我不能告诉COM Interop要使用哪个版本的Excel?

openxml传播保存为

我有一个Excel 2007电子表格,我用OpenXML SDK 2编辑。我删除了一些行等,我想知道如何将该Spreadsheetdocument保存到另一个文件名。

自动化加载项与COM加载项

我是附加程序的新手,需要以下scheme的帮助: 我有一个C#Excel自动化插件,它调用几个UDF 。 在自动加载项加载期间,我想要进行用户名和密码检查,在加载项加载时,用户可以input其详细信息的屏幕必须popup。 如何使用自动化加载项来完成? 如何使用自动化插件一般地完成事件处理? 我想要在用户按下F9来计算一些单元格中的UDF公式时进行一些计算。 是否有任何文章解释了自动化插件中的事件处理?

如何加快将DataTable转储到Excel工作表?

我有以下例程将DataTable转储到Excel工作表中。 private void RenderDataTableOnXlSheet(DataTable dt, Excel.Worksheet xlWk, string [] columnNames, string [] fieldNames) { // render the column names (eg headers) for (int i = 0; i < columnNames.Length; i++) xlWk.Cells[1, i + 1] = columnNames[i]; // render the data for (int i = 0; i < fieldNames.Length; i++) { for (int j = 0; […]

c#,Excel + CSV:如何获得正确的编码?

我已经尝试了很长一段时间,但无法弄清楚。 我试图通过* .csv文件将数据导出到Excel。 到目前为止效果很好,但在Excel中打开文件时遇到一些编码问题。 (左边的原始string,右边的EXCEL结果): Messwert(µm / m) ==> Messwert(µm / m) Dümme Mässöng ==> Dümme Mässöng 记事本+ +告诉我,该文件编码“ANSI为UTF8”(WTF?) 所以这里有不同的方法,我试图得到一个有效的结果:明显的实现: tWriter.Write(";Messwert(µm /m)"); 更复杂的一个(尝试大概十几个或更多的编码组合:) tWriter.Write(Encoding.Default.GetString(Encoding.Unicode.GetBytes(";Messwert(µm /m)"))); tWriter.Write(Encoding.ASCII.GetString(Encoding.Unicode.GetBytes(";Messwert(µm /m)"))); 等等 创build数据的方法的整个源代码: MemoryStream tStream = new MemoryStream(); StreamWriter tWriter = new StreamWriter(tStream); tWriter.Write("\uFEFF"); tWriter.WriteLine(string.Format("{0}", aMeasurement.Name)); tWriter.WriteLine(aMeasurement.Comment); tWriter.WriteLine(); tWriter.WriteLine("Zeit in Minuten;Messwert(µm / m)"); TimeSpan tSpan; foreach (IMeasuringPoint tPoint in […]

如何selectc#的Excel.Range对象中的工作表中的所有单元格?

我试图selectExcel中的所有单元格的Excel.Range对象的C#应用​​自动拟合,边框等我有一些合并的单元格内的单元格。 有没有简单的伎俩这样做?

以编程方式访问Excel自定义文档属性

我试图将自定义属性添加到我已经编程创build的工作簿。 我有一个方法来获取和设置属性,但问题是工作簿正在为CustomDocumentProperties属性返回null。 我不知道如何初始化此属性,以便我可以从工作簿添加和检索属性。 Microsoft.Office.Core.DocumentProperties是一个接口,所以我不能去做下面的事情 if(workbook.CustomDocumentProperties == null) workbook.CustomDocumentProperties = new DocumentProperties; 这是我必须得到的代码,并设置属性: private object GetDocumentProperty(string propertyName, MsoDocProperties type) { object returnVal = null; Microsoft.Office.Core.DocumentProperties properties; properties = (Microsoft.Office.Core.DocumentProperties)workBk.CustomDocumentProperties; foreach (Microsoft.Office.Core.DocumentProperty property in properties) { if (property.Name == propertyName && property.Type == type) { returnVal = property.Value; } DisposeComObject(property); } DisposeComObject(properties); return returnVal; } protected void […]

使用EPPlus生成的Excel文件中的不可读内容

使用EPPlus库从模板生成Excel文件时遇到了一些问题。 该文件具有第一个电子表格,其中包含用于填充下表中的数据透视表的数据。 当我打开生成的文件时,出现以下错误信息:“Excel中发现'sampleFromTemplate.xlsx'中的不可读内容。是否要恢复此工作簿的内容?我相信此工作簿的来源,单击是。 我显然是单击是,然后得到对文件进行修复的摘要,并链接到一个XML格式的日志文件,其中包含: <?xml version="1.0" encoding="UTF-8" standalone="true"?> <recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> <logFileName>error095080_01.xml</logFileName> <summary>Errors were detected in file 'C:\TEMP\sampleFromTemplate.xlsx'</summary> <repairedRecords summary="Following is a list of repairs:"> <repairedRecord>Repaired Records: Table from /xl/tables/table1.xml part (Table)</repairedRecord> </repairedRecords> </recoveryLog> 这显然是由我在代码中定义的指定范围(“Table1”)引起的,以指示要用于数据透视表的数据。 在名为“Table1”的模板中已经有一个“Table Name”,但是我似乎无法通过ExcelPackage.Worksheet.Names集合来访问它。 作为EPPlus的新人,并没有用Excel做很多实验,我不明白我做错了什么。 以下是我生成文件的一些代码: private string GenerateFromTemplate(string fileName, string templateName, DataTable tab) { FileInfo newFile = new FileInfo(string.Format("C:\\MyPath\\{0}.xlsx", fileName)); FileInfo templateFile […]

“Microsoft.ACE.OLEDB.12.0”提供程序未在本地计算机(服务器)上注册

我知道这个问题有十几个答案和post,但没有任何作品适合我。 我有我的MVC 5应用程序,我将它部署到我的服务器的IIS 7.5。 应用程序运行良好,一切工作,直到我去使用ACE.OLEDB行动。 我得到这个错误: [InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.] System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr, DataSourceWrapper& datasrcWrapper) +1785474 System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +1802032 System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +100 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +61 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) […]

从excel文件打开xml读取

我想在我的项目中实现openXml sdk 2.5。 我在这个环节做了一切事情 using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Spreadsheet; using System.IO.Packaging; static void Main(string[] args) { String fileName = @"C:\OPENXML\BigData.xlsx"; // Comment one of the following lines to test the method separately. ReadExcelFileDOM(fileName); // DOM //ReadExcelFileSAX(fileName); // SAX } // The DOM approach. // Note that the code below works only for cells that […]