简体   繁体   中英

Issue with an example in “How to transfer data to an Excel workbook ”

http://support.microsoft.com/kb/306023 it's the first example: "Use Automation to Transfer Data Cell by Cell" Below are the variables I declared for the example.

Excel.Application m_objExcel;
Excel.Workbooks m_objBooks;
Excel._Workbook m_objBook;
Excel.Sheets m_objSheets;
Excel._Worksheet m_objSheet;
Excel.Range m_objRange;
string m_strSampleFolder = @"C:\VBtest\PRACTICEProgramming\INDIVIDUALprograms\EXCEL";
string m_objOpt = @"C:\VBtest\PRACTICEProgramming\INDIVIDUALprograms\EXCEL";
Excel.Font m_objFont;

Basically everything runs fine. The issue is when the app is running, I get an error message.

"COMException was unhandled

Excel cannot access 'EXCEL'. The document may be read-only or encrypted."

I'm thinking the value I declared for m_objOpt is declared wrong or it doesn't like the value. I tried creating a premade .XLS file but that doesn't work. I also tried putting a name for the xls but the add method wants to find the xls in the default path which I don't want.

I don't know what I can do to fix it.

看起来您缺少m_objOpt结尾的文件扩展名...您可以尝试向其中添加.xls或.xlsx或其他有关文件扩展名的内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM