excel-interop

Excel Automation Windows Service

自古美人都是妖i 提交于 2019-12-02 06:22:13
问题 I have a Windows Service that runs the Excel Interop in order to automate the execution of various macros. However, I am running in a peculiar issue when I try to run a macro which access a database using Windows Authentication ... If the macro is run through the Windows Service , the workbook is opened and the macro is execution is started but the application hangs (presumably at the data access portion). If, however, the macro is run through the Visual Studio debugger , using the same

Excel Automation Windows Service

断了今生、忘了曾经 提交于 2019-12-02 01:25:00
I have a Windows Service that runs the Excel Interop in order to automate the execution of various macros. However, I am running in a peculiar issue when I try to run a macro which access a database using Windows Authentication ... If the macro is run through the Windows Service , the workbook is opened and the macro is execution is started but the application hangs (presumably at the data access portion). If, however, the macro is run through the Visual Studio debugger , using the same implementation as the service (they call the same class library), it executes, saves the workbook, and

Interop Excel UsedRange Rows Count incorrect

╄→尐↘猪︶ㄣ 提交于 2019-12-01 21:20:03
I am trying to read an excel spreadsheet into memory but when I use worksheet.UsedRange.Rows.Count, the value return is incorrect. I have 1670 rows of data in my spreadsheet but the row count brings back 694 rows. var excelApp = new Microsoft.Office.Interop.Excel.Application {Visible = false}; var workbook = excelApp.Workbooks.Open(_mirrorFileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); var worksheet = (Worksheet)workbook.Worksheets[1];

Excel Interop - How to change named range

拈花ヽ惹草 提交于 2019-12-01 19:27:48
问题 I have a template excel file that I fill data into from SQL Server OLEDB connector. The file contains some pivot tables that refer to the dataset being filled in by the database. Currently what I do is that I select all rows in sheet by using "Data!$A:$K" range. This brings a problem with blank values being shown in the pivot table. What I wanted to do is to create a named table over the dataset and refer the pivot tables to that (plus I gain some other advantages that names tables bring).

How to debug slow Office application interop constructor?

耗尽温柔 提交于 2019-12-01 14:32:47
问题 I have an application which deals with excel. Recently I encountered a problem with very slow creation of Excel object. I've recreated the issue with this simple code: Microsoft.Office.Interop.Excel.Application xlApp; xlApp = new Microsoft.Office.Interop.Excel.Application(); The second line causes the delay. In order to measure the time needed for new object allocation, above code has been extended with time tracking solution and the results are conclusive. In NORMAL situation, above code

Using Interop.Excel to check if Excel file contains VBA Macros

百般思念 提交于 2019-12-01 09:37:14
问题 In my application I have to check if a excel-document contains vb-macros. So I've written the following method to check the excel-document: internal static bool ExcelContainsMacros(string pathToExcelFile) { bool hasMacros = true; Microsoft.Office.Interop.Excel._Application excelApplication = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook workbooks = null; try { object isReadonly = true; workbooks = excelApplication.Workbooks.Open( pathToExcelFile,

Closing an Excel Workbook

我的未来我决定 提交于 2019-12-01 06:12:59
I have a bit of code that opens an xls workbook; Excel.Workbooks workBooks; workBooks = excelApp.Workbooks; workbook = workBooks.Open(sourceFilePath + sourceFileName + ".xls"); I then get the work sheet; worksheets = workbook.Worksheets; worksheet = worksheets.get_Item("Standard"); I then save the file as a csv; worksheet.SaveAs(sourceFilePath + sourceFileName + ".csv", Excel.XlFileFormat.xlCSVWindows, Type.Missing, Type.Missing, false, false, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing); Then I try to close the workbook; Marshal.FinalReleaseComObject

Closing an Excel Workbook

南楼画角 提交于 2019-12-01 04:38:24
问题 I have a bit of code that opens an xls workbook; Excel.Workbooks workBooks; workBooks = excelApp.Workbooks; workbook = workBooks.Open(sourceFilePath + sourceFileName + ".xls"); I then get the work sheet; worksheets = workbook.Worksheets; worksheet = worksheets.get_Item("Standard"); I then save the file as a csv; worksheet.SaveAs(sourceFilePath + sourceFileName + ".csv", Excel.XlFileFormat.xlCSVWindows, Type.Missing, Type.Missing, false, false, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing

Cannot implicitly convert type 'object' to 'Microsoft.Office.Interop.Excel.Worksheet'. An explicit conversion exists (are you missing a cast?)

强颜欢笑 提交于 2019-12-01 04:23:15
Here I'm opening excel and writing to excel sheet. I'm changing my windows application to asp website and seen this error. I have added all the references and libraries. Don't know what I am missing here. Getting error as mentioned below. Please help me. 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 } you have to create a new

Microsoft.Office.Interop.Excel.ApplicationClass has no constructor defined

时光毁灭记忆、已成空白 提交于 2019-12-01 02:46:54
I tried to follow How to open an Excel file in C# tutorial, i.e. added a reference on the Com tab to Microsoft Office 14.0 Object Library and tried to compile code: using Excel = Microsoft.Office.Interop.Excel; //... Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; xlApp = new Excel.ApplicationClass();//error here //... and faced a compile-time error, saying There is no constructor defined for Microsoft.Office.Interop.Excel.ApplicationClass type. What am I missing? Try this: Excel._Application xlApp = new Excel.Application(); Use the following to open it: xlApp