作者chrishappy11 ()
看板C_Sharp
标题[问题] 请问如何将excel里cell转型?
时间Fri May 17 23:36:27 2013
请各位高手
我目前用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
1F:→ soup514:((Range)o_sheet.Cells[40+n1,3]).Text == "RC" 05/18 11:43
2F:→ soup514:Text.tostring 还是外包convert.tostring 随便 05/18 11:46
什麽意思...不太了解??
※ 编辑: chrishappy11 来自: 219.70.144.106 (05/18 12:30)
3F:→ piadoro:我怎麽印象中要用value取值@@... 05/19 14:28
4F:→ piadoro:1F的意思是你要先转型才能取.Text 你先取text才转会挂掉 05/19 14:29
其实我有试过value,value2 但一样的错误讯息
※ 编辑: chrishappy11 来自: 119.14.168.8 (05/21 19:04)
5F:→ Zuexx:Microsoft interop容易造成system lock, 建议参考一下NPOI作 05/24 22:12