Tag: interop

为什么Application.get_Caller(Type.Missing)返回一个负整数?

get_Caller(Type.Missing)方法有些奇怪。 它返回一个负整数-2146826265 ,而不是Range对象。 有没有人遇到过这个问题? 为什么呢,我该如何解决呢? 谢谢。 Excel.Range range = (Excel.Range) application.get_Caller(System.Type.Missing); 上面的代码将失败,如果我尝试显式用户typesExcel.Range 。 错误消息说,'不能将types'int'转换为'Microsoft.Office.Interop.Excel.Range'。 编辑: 获取单元的调用者的意图是将其传递给我的以下function: private string getResultFromResultSheet(Excel.Range originalSheetRange, Excel.Worksheet resultSheet) { string DataResult = ""; try { string os_currentAddress = originalSheetRange.get_Address(Type.Missing, Type.Missing, Excel.XlReferenceStyle.xlA1, Type.Missing, Type.Missing); Excel.Range currentRRange = null; currentRRange = resultSheet.get_Range(os_currentAddress, Type.Missing); if (currentRRange != null) { if (string.IsNullOrEmpty(Convert.ToString(currentRRange.Value))) DataResult = ""; […]

Excel C#COM插件返回一个数组与date和双打

我的C#Excel插件正在将时间序列转换为另一个时间序列。 时间序列被定义为两列的范围,第一列是date,第二列是浮点数。 尽pipe我的C#代码返回DateTime作为date,但Excel将其转换为以date表示的Exceldate,显示的值是整数,例如39000,而不是date格式,例如14/12/2012。 因此,用户必须按CTRL +#将其变成date。 有没有办法以某种方式返回一个已经格式化为Exceldate的Excel的Excel插件的输出?

如何将sheet1中的数据移动到excel中的sheet2

我通过C#将内容写入Excel文件。 我在Excel中有4列和许多行。 当应用程序运行时,我需要检查数据是否存在于sheet1中,然后它应该被移动到sheet2。 如果sheet2也包含数据,则应该附加sheet2数据。 我正在使用interop dll访问excel。 我已经完成了写内容,但我怎样才能以编程方式移动它? 这是我的尝试。 Excel.Workbook xlwb; Excel.Application excelApp = new Excel.Application(); Excel.Worksheet xlssheet1; Excel.Worksheet xlssheet2; xlwb = excelApp.Workbooks.Open(myPath, objMissing, objMissing, objMissing, objMissing, objMissing, objMissing, objMissing, objMissing, objMissing, objMissing, objMissing, objMissing, objMissing, objMissing); int rowIndex = 2; int colIndex = 1; if (excelApp.Cells[rowIndex, colIndex] != null) { xlssheet1 = (Worksheet)xlwb.Worksheets[1]; xlssheet2 = […]

在互操作后让Excelclosures

我有一个应用程序,从Excel电子表格中吸取一些数据。 我无法把它清理得很好。 EXCEL.EXE继续运行。 我读过其他职位,说你需要对所有的COM对象Marshal.ReleaseComObject() 。 我相信我正确地做到了这一点。 为了使事情更清洁,我已经删除了错误检查代码(与Excel没有关系),但是这是代码: public override MarketPriceItem[] GetMarketPrices() { string[] files = Directory.GetFiles(ConfigurationManager.AppSettings["XXSpreadsheets"]); Excel.Application app = new Excel.Application { Visible = false }; List<MarketPriceItem> prices = new List<MarketPriceItem>(); Excel.Workbooks workbooks = app.Workbooks; foreach (string filename in files) { Excel.Workbook wb = null; wb = workbooks.Open(filename); Excel.Worksheet sheet = wb.Sheets[1]; cell = sheet.Cells[1, […]

C# – 是否可以使用函数信函(A1)与workSheet.Cells?

我最近使用PowerShell来自动化一些东西,我可以简单地使用A1,A2等与C#,似乎是使用[1,1],(坐标样式)的要求,否则你会得到一个types不匹配。 这是我正在使用的代码: //Generating User and Password int startCoordI = Int32.Parse(startCoord); int endCoordI = Int32.Parse(endCoord); int userCoordI = Int32.Parse(userCoord); int passwordCoordI = Int32.Parse(passwordCoord); int value = startCoordI; string Username = Convert.ToString(workSheet.Cells[userCoord, startCoordI].Value); MessageBox.Show(Username); string Password = Convert.ToString(workSheet.Cells[passwordCoord, startCoordI].Value); MessageBox.Show(Password); try { for (I = startCoordI; I <= endCoordI; I++) { System.Diagnostics.ProcessStartInfo proccessStartInfo = new System.Diagnostics.ProcessStartInfo("net", "user […]

使用Excel Interop对行中使用的单元格进行计数

我想在工作表中的每一行中获取最后使用的单元格的索引。 我可以得到最后使用整个工作表的列,但我有每个行中有不同的使用单元格的表,如下所示: 我试过这个: var excelApp = new Excel.Application(); var workBook = excelApp.Workbooks.Open(excelFilePath); Excel._Worksheet worksheet = workBook.Worksheets[worksheetName]; int rowsCount = worksheet.UsedRange.Rows.Count; for (int i = 1; i <= rowsCount; i++) { Excel.Range range = worksheet.Rows[i]; int lastColumn = range.Columns.Count; Console.WriteLine(lastColumn); } 我期待输出: 3 5 2 7 但实际产出是: 16384 16384 16384 16384 我使用Excel Interop库。 任何build议,将不胜感激。 谢谢!

C#使用Excel Interop更新公式

我有一个C#应用程序,从现有的模板构buildExcel文件。 在模板上,我希望我的行总数/平均数已被更新,然而许多行被应用程序插入(在页眉和页脚行之间)。 这应该是简单的,但我试图记住如何做这样的事情画空白。

C#在Excel中打开csvstring而不保存string

我有一个csv格式的string,我希望只需在Excel中打开,而不必先保存文件。 这可能吗? 我看了一下Interop,但找不到我需要的具体方法。 谢谢。

Microsoft Office Interop Excel – 指定Excel文件的名称

我使用Microsoft Office Interop Excel来创buildexcel文件。 我的问题是,我不知道如何指定excel文件的名称。 variables: // Excel object references. private Application _excelApp; private Workbooks _books; private _Workbook _book; private Sheets _sheets; private _Worksheet _sheet; 创buildexcel文件: _excelApp = new Application(); _books = _excelApp.Workbooks; _book = _books.Add(_optionalValue); _sheets = _book.Worksheets; _sheet = (_Worksheet)(_sheets.Item[1]); _sheet.Name = sheetName; 如何在创buildexcel文件时指定excel文件的名称? 对不起我的英语不好。 编辑: 我知道我可以使用 _book.SaveAs(fileName)

如何在“另存为”对话框中将工作表的默认保存格式从.xml更改为.xls?

我不想在工作表打开后立即显示“另存为”对话框,我想要更改菜单中对话框的默认格式。