看板 C_Sharp 關於我們 聯絡資訊
請各位高手 我目前用C#來自動化控制excel 但有牽扯到計算及identify cell內的文字 所以我必需要將cells內轉型 程式碼如下: _Application o_excel = null; _Workbook o_book = null; _Worksheet o_sheet = null; o_excel = new Microsoft.Office.Interop.Excel.Application(); o_book = o_excel.Workbooks.Add(); o_excel.Visible = true; o_excel.DisplayAlerts = true; o_sheet = o_book.Worksheets[1]; o_sheet.Columns.ColumnWidth = 2; o_sheet.Rows.RowHeight = 15; o_sheet.Cells.Replace("S", "RC"); while (Convert.ToString((Microsoft.Office.Interop.Excel.Range)o_sheet.Cells[40 + n1 ,3].Text) =="RC") { n1++; } for (int i = 0; i <= 31; i++) { o_sheet.Cells[20, 68 - i] = o_sheet.Cells[41 + n1 + i, 10]; } 我實際compile後確出現下列錯誤 Additional information: Cannot convert type 'string' to 'Microsoft.Office.Interop.Excel.Range' 請問我該怎麼解決??? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.70.144.106
soup514:((Range)o_sheet.Cells[40+n1,3]).Text == "RC" 05/18 11:43
soup514:Text.tostring 還是外包convert.tostring 隨便 05/18 11:46
什麼意思...不太暸解?? ※ 編輯: chrishappy11 來自: 219.70.144.106 (05/18 12:30)
piadoro:我怎麼印象中要用value取值@@... 05/19 14:28
piadoro:1F的意思是你要先轉型才能取.Text 你先取text才轉會掛掉 05/19 14:29
其實我有試過value,value2 但一樣的錯誤訊息 ※ 編輯: chrishappy11 來自: 119.14.168.8 (05/21 19:04)
Zuexx:Microsoft interop容易造成system lock, 建議參考一下NPOI作 05/24 22:12