Tag: .net

Excel VSTO AddIn – 从select中获取图表对象

我将如何将用户的select转换为VSTO Excel加载项中的图表对象(如Excel.Chart )。 我一直在尝试使用这样的东西(同时在Excel中select一个图表对象): Dim chart as Excel.Chart = CType(Globals.ThisAddIn.Application.Selection, Excel.Chart) 但是,这会引发InvalidCastException 。 我似乎无法find任何有关如何让用户select图表,然后在VSTO加载项中修改所选图表的文档。

Asp.net WebApi Aspose.Cells – 导出和下载excel

我使用Aspose.Cells来创buildexcel文件。 其实我试图保存磁盘上的xls文件,我无法解决这个问题。 这是我的get方法。 [Route("xls")] [HttpGet] public HttpResponseMessage Export() { try { string dataDir = KnownFolders.GetPath(KnownFolder.Downloads); //var workbook = TransferService.Export(); //TODO get xml Workbook workbook = new Workbook(); var stream = workbook.SaveToStream(); // I need save this workbook return Request.CreateResponse(HttpStatusCode.OK); //it's not important here } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.InternalServerError); //it's not important here } […]

如何不挂Excel?

我有这个问题,我的易失性,macros型UDF设置调用单元格旁边的几个单元格的值完美工作,除非在工作表中使用两次(或更多):Excel状态栏开始闪烁“正在计算…” 。 我不是一个真正的挂起,而是一个沉重的重新计算:在示例函数的计数器绘制没有实际挂起的琐碎。 此外,我不确定使用易失性UDF,因为我需要自动重新计算,但只能在input更改,而不是不断的轮询。 我做了三个function的示例模块: VolatileNyanCat – 类似于我的UDF:一个SetValue调用。 如果使用两次, Excel挂起 。 NonVolatileOneNyanCat – 如上,但不易变。 不挂,但我需要自动重新计算。 HangNyanCat – 它在两个不同的范围内两次调用SetValue 。 Excel挂起。 我认为这与ExcelAsyncUtil.QueueAsMacro如何工作和线程安全有关,但我在这里感到困惑。 Imports ExcelDna.Integration Imports ExcelDna.Integration.XlCall Public Module Example <ExcelFunction(IsMacroType:=True, IsVolatile:=True)> Public Function VolatileNyanCat() As String Dim caller = CType(XlCall.Excel(XlCall.xlfCaller), ExcelReference) Dim NyanCat(,) As String = {{"Nyan", "Cat"}} Dim nc As New ExcelReference(caller.RowFirst + 1, caller.RowLast […]

如何编写用于VBA Excel的C#UDF的安装程序

基本上,我知道如何在C#中为VBA编写用户定义的函数( 这里 )我想写一个安装程序,它将执行必要的操作,以便在任何Excel文档中自动激活和引用我的* .tlb。 有关registry项或设置的任何信息将会有所帮助 编辑:以下我生成一个MyPj.tbl和一个MyPj.dll(感谢msbuild)。 [InterfaceType(ComInterfaceType.InterfaceIsDual)] [Guid("afb62cb2-dfa8-4f0f-980b-25f96ad93b92")] public interface IGreeting { string SayHelloWorld { get; } } [ClassInterface(ClassInterfaceType.AutoDual)] [Guid("8cd91f78-4e62-4a12-95e0-df82699d4d75")] [ProgId("TestDll.Test")] public class Greeting : IGreeting { public string SayHelloWorld { get { return "Hello, World! "; } } } 通过将生成的.tbl添加到我在Excel中的项目(工具>参考…>浏览),我可以访问Excel VBMacro中的MyPj.Greeting Sub Test() Dim greeter as New MyPj.Greeting MsgBox greeter.SayHelloWorld() End Sub 重点是我不想通过“工具>参考…>浏览”。 我需要做一个安装程序,它会自动在Excel中提供“SayHelloWorld”

如何将date与行匹配,然后使用EPPlus获取最终的列值?

到目前为止,我可以从电子表格中轻松获取数据,只是获取参考号码行,但是我目前不知道如何在获取正确的数据之前将行匹配到数据部分。 我目前不得不从下面的Excel电子表格中提取一些数据: Start date Ref number 29/07/2015 2342326 01/07/2016 5697455 02/08/2016 3453787 02/08/2016 5345355 02/08/2015 8364456 03/08/2016 1479789 04/07/2015 9334578 主要的问题是,是否可以从设定的date读取数据,从行中获取参考号码,例如开始date。 例如,如果我只是想从date设置的数据上个月1日以上。 这将如何最好地实施。 使用基本的OleDb获取列的当前代码示例: using System; using System.Data.OleDb; using System.Text.RegularExpressions; namespace Number_Cleaner { public class NumberCleanerReport { public void runExcel_Report() { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("[*][START OF: NumberExt.xls, Number Extraction]"); Console.ResetColor(); string con = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NumberExt.xls;" […]

如何使用get_range方法为特定行和特定范围的列着色Excel表

我试图使用下面的C#代码颜色现有的Excel文件…我能够着色一个列的单元格的范围,但我需要为该列范围的特定行着色。 这怎么能实现? 例如:我需要为第二行的列范围(“AW:AW”,“AY:AY”) excelWorkSheet5.get_Range("AW:AW", "AY:AY").Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);

从date范围中剥离EPPlus输出中的数据

快速浏览:主要目标是从行中读取设定date的数据,并从设定的date(例如开始date)获取参考编号。 例如,如果我只是想从date设置的数据上个月1日以上。 我目前不得不从下面的Excel电子表格中提取一些数据: Start date Ref number 29/07/2015 2342326 01/07/2016 5697455 02/08/2016 3453787 02/08/2016 5345355 02/08/2015 8364456 03/08/2016 1479789 04/07/2015 9334578 使用EPPlus输出: 29/07/2015 2342326 29/07/2016 5697455 02/08/2016 3453787 02/08/2016 5345355 02/08/2015 8364456 03/08/2016 1479789 04/07/2015 9334578 这部分是好的,但是当我尝试通过date范围去除输出我得到错误,例如使用LINQ我得到以下错误输出。 An unhandled exception of type 'System.InvalidCastException' occurred in System.Data.DataSetExtensions.dll Additional information: Specified cast is not valid. LINQ代码: var […]

我怎样才能得到某些细胞的背景值?

我试图创build一个ExcelReference,然后调用GetValue(),但这会导致XlCallException(exception中没有提供的细节)。 var val = new ExcelReference(1, 1).GetValue(); 我究竟做错了什么?

获取文档加载后调用的事件

如何创build一个方法,在文档加载后立即调用(使用Excel-DNA)? Excel-DNA中是否支持这种function?

格式化十进制前的2位数字和十进制后的2位数字,Excel Interop

我想从Excel电子表格中的单元格中读取数值 10.50 20.25 41.10 我正在使用Excel Interop来检索值。 下面的工作值小于10,但是当10或更大的值被设置为0.我怎样才能正确格式化使用NumberFormat行动? double doubleHours = 0.0; if (Extension.IsNumeric(excelWorksheet.Cells[rowCount, columnCount].Text)) { Excel.Range range = excelWorksheet.Cells[rowCount, columnCount]; range.EntireColumn.NumberFormat = "#,##0.00"; double.TryParse(excelWorksheet.Cells[rowCount, columnCount].Text, out doubleHours); //continue processing }