我怎样才能提取Excel单元格的字符串? [英] How can I extract a string from an excel cell?
本文介绍了我怎样才能提取Excel单元格的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何写一个单元格,但我怎么办得到一个excel写的细胞内已经存在的字符串文件转换成字符串对象,所以我可以用它在其它细胞生成数据?
I know how to write to a cell, but how do I get an already existing string written inside a cell in an excel file into a string object so I can use it to generate data in other cells?
我到目前为止的代码:
Excel.ApplicationClass excelApp = new Excel.ApplicationClass();
excelApp.Visible = true;
Excel.Workbook excelWorkbook = excelApp.Workbooks.Open("C:\\Users\\user\\Desktop\\list.xls", 0, false, 5, "", "",
false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
Excel.Sheets excelSheets = excelWorkbook.Worksheets;
string currentSheet = "Sheet1";
Excel.Worksheet xlws = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
我可以使用像操纵单元格的内容:
I can manipulate cell contents using something like:
xlws.Cells [1,1] =富;
但我有麻烦反其道而行之,即读单元格内容到我的程序字符串。
But I'm having trouble doing the opposite, that is reading cell contents into a string in my program.
任何帮助,将不胜感激。
Any help would be appreciated.
推荐答案
<击> 字符串的myString = xlws.Cells [1,1]。价值为字符串;
击>
字符串的myString =((Excel.Range)workSheet.Cells [1,1])Value2.ToString();
这篇关于我怎样才能提取Excel单元格的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文