Tag: .net

以编程方式识别Excel版本

我的VB.NET(3.5)应用程序生成Excel报告。 较新版本的Excel支持Office Open XML文件格式,而旧版本则不支持。 我希望我的应用程序能够识别本地计算机上安装了哪个版本的Excel,并使用不同的方法来生成报告(较新的版本:通过生成一个XML文件。旧版本:利用Excel自动化)。 我如何识别安装在本地机器上的Excel版本?

.Net中的Excel样式条件数字格式

我需要使用Excel条件格式string在.Net应用程序中格式化数字。 对于那些不熟悉它们的人来说,Excel格式string看起来像这样: [>=2]#,##0.0;[<=-2]-#,##0.0;#,##0.00 …应该被解释为“对于大于2的数字使用第一格式,对于低于-2的数字使用第二格式,对于其他任何情况使用第三格式”。 在我继续构build我自己的自定义格式stringparsing器之前,有没有人知道在.Net中是否有类似这样的东西,我可以使用? 我知道有格式化string的分隔符,但是据我所知,似乎没有考虑到“是负数/正数/零”的情况。

Excel进程不会closures

一旦完成使用,我无法使EXCEL(32)进程closures。 正如你可以在下面的代码中看到的,一旦ProcessRFAFData函数完成其执行,EXCEL进程不会closures(我仍然可以在任务pipe理器中看到EXCEL.EXE*32 )。 由于这个原因,当SaveErrors开始执行时,我得到以下exception: System.Runtime.InteropServices.COMException (0x800A03EC): Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space. • To make more memory available, close workbooks or programs you no longer need. • To free disk space, delete files you no longer need from the disk you […]

不能将types“对象”隐式转换为“Microsoft.Office.Interop.Excel.Worksheet”。 存在明确的转换(您是否缺less演员?)

在这里我打开excel并写入excel表单。 我正在改变我的Windows应用程序到ASP网站,看到这个错误。 我已经添加了所有的参考和库。 不知道我在这里错过了什么。 获得如下所述的错误。 请帮帮我。 Excel.Application excel = new Excel.Application(); excel.Visible = false; // to hide the processing Excel.Workbook wb = excel.Workbooks.Add(); Excel.Worksheet sh = wb.Sheets.Add(); // Error at wb sh.Name = "Links"; for (int i = 1; i < list.Count; i++) { sh.Cells[i.ToString(), "A"].Value2 = list[i]; //Error at .Value2 }

将Excel电子表格编译成.NET程序集的方法?

我有一个电子表格,我想编译成一个可以从C#调用的表单。 当然,我希望能够在读取计算结果之前将input更改为电子表格。 你推荐的方法是什么? 更新: 为了澄清,我想做一个现有的Excel电子表格作为可从.NET调用的Web服务提供。 我不能依赖Excel,因为它在Web服务器上运行。 更新: 我用下面的答案,它像一个魅力。 现在我可以在Excel中创build公式原型,然后直接将其转换为C#并将其编译为程序集。 将Excel文件作为服务器进程读取也包含此问题。

使用Excel = Microsoft.Office.Interop.Excel编译错误

在我的MVC 5应用程序中,我想使用Microsoft.Office.Interop.Excel库。 我使用了Visual Studio 2013和Office 2013.我添加了一个参考Microsoft.Excel 15.0 Object Library并在我的课程中添加了using Excel = Microsoft.Office.Interop.Excel; 当我点击build它不显示任何错误,并告诉Build Complete ,但是当我运行我的应用程序,我得到这个错误 Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS1748: Cannot find the interop type that […]

Excel INT等效

我正在寻找以下Excel公式的C#等价物: (INT(((4800/1000)/0.415)*2.393)/0.05) 我在Excel中获得了上述公式的值540 ,但是现在我正在尝试在C#中使用以下代码执行相同操作: Math.Round((((4800 /1000) / 0.415) * 2.393) / 0.05, 0) 我得到价值553 。 我怎样才能获得与我的C#编码相同的价值?

杀死一个interop应用程序进程

我有一个程序(用VB.NET编写)中的以下内容: Imports Microsoft.Office.Interop.Excel Public Class Form1 Dim eApp As New Excel.Application Dim w As Excel.Workbook w = eApp.Workbooks.Open( "path.xls", ReadOnly:=True) .. Processing Code .. //Attempts at killing the excel application w.Close() eApp.Workbooks.Close() eApp.Quit() End Class 当我运行这个几次时,我在任务pipe理器中得到了一堆EXCEL.EXE实例。 我怎样才能杀死代码中的这些进程? 代码中的所有代码都已经尝试过,并没有工作。

将C#列表列表导出到Excel

使用C#,有没有一种直接的方式来导出列表(即List<List<T>> )到Excel 2003列表? 我parsing出大的文本文件并导出到Excel。 一次写入一个单元会造成太多的开销。 我select使用List<T>以便我不必担心指定行数或列数。 目前,我一直等到文件结束,然后把我的List<List<object>>放到一个二维数组中。 然后可以将数组设置为Excel.Range对象的值。 它的工作原理,但似乎我应该能够拿我的列表清单,而不必担心行数或列的数量,并将其转储到工作表从A1到任何地方。 以下是我想replace或改进的代码片段: object oOpt = System.Reflection.Missing.Value; //for optional arguments Excel.Application oXL = new Excel.Application(); Excel.Workbooks oWBs = oXL.Workbooks; Excel._Workbook oWB = oWBs.Add(Excel.XlWBATemplate.xlWBATWorksheet); Excel._Worksheet oSheet = (Excel._Worksheet)oWB.ActiveSheet; int numberOfRows = outputRows.Count; int numberOfColumns = int.MinValue; //outputRows is a List<List<object>> foreach (List<object> outputColumns in outputRows) { if (numberOfColumns < […]

无法closures从VB.NET应用程序的Excel进程

我创build了下面的类来打开并收集excel文件中的工作表名称。 它在打开文件和返回每个单独工作表的名称时应该如此。 不幸的是,我无法closures文件。 这使Excel.exe进程挂起。 即使在我试图closures它在这个类的底部,过程仍然挂起。 我必须手动转到Windows任务pipe理器并杀死该进程,然后才能再次使用该文件。 即使我退出应用程序,它仍然在那里。 任何关于如何从代码中杀死这个过程的build议? Imports Excel = Microsoft.Office.Interop.Excel Public Class ExcelWrapper Dim strTypeSelection As String = String.Empty Dim strFilePath As String = String.Empty Function GetWorksheetsByName(ByVal strfilePath As String) As Array Dim xlsApp As Excel.Application Dim xlsWorkBook As Excel.Workbook xlsApp = New Excel.Application xlsWorkBook = xlsApp.Workbooks.Open(strfilePath) Dim intWsCount As Integer = xlsApp.Worksheets.Count […]