0
所以我在Visual Studio 2013中工作,我試圖返回工作表中給定單元格中的字符串。C#Visual Studio中的Excel COM
public StringBuilder MyCellData(int rCnt, int cCnt)
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
StringBuilder str = new StringBuilder("");
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(@"C:\Users\james.naughton\Documents\Visual Studio 2013\Projects\QA_Automation\QA_Automation\copyChangeReportWAccountID.xlsx", 0, true, 5, "Landeck1", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Sheets.get_Item(1);
range = xlWorkSheet.UsedRange[rCnt,cCnt];
str.Append((range.Item[rCnt, cCnt]).ToString());
return str;
現在,每當我運行程序出於某種原因對範圍和xlWorkSheet值始終COM對象,所以當它沒有返回什麼,我想它。有關如何訪問正確的工作表並從單元返回數據的任何建議?
謝謝, 詹姆斯