Office.Interop.Excel 生成 excel 报告。
我有预定义的 excel 模板,我正在使用 Microsoft.Office.Interop.Excel 对象加载和替换文本。我的问题是,当我使用部分文本在 excel 工作表中搜索单元格时,它不起作用,但在我的旧 VB 6 代码中它工作正常,我的代码就像在 VB6 中工作而在 c#.4 中不工作
我需要找到的 Excel 表单元格
行“2”,列“D”有文本“«名称»”
VB 6 代码(工作)
Dim m_objExcelSheet As Object
Dim objRange As Object
'Note : here has extra code to load Excel template file
'When I use only part of text to find cell its working fine
objRange = m_objExcelSheet.cells.Find(what:=Chr(171))
c#.net 4.0(不工作)
Microsoft.Office.Interop.Excel._Worksheet objExcelSheet;
Microsoft.Office.Interop.Excel.Range objRange ;
//Note : here has extra code to load Excel template file
//This doesn't work, it returns null
objRange = objExcelSheet.Cells.Find((char)(171), LookAt: Microsoft.Office.Interop.Excel.XlLookAt.xlPart);
//I tried this as well but this also doesn't work
objRange = objExcelSheet.Cells.Find((char)(171), Type.Missing,
Microsoft.Office.Interop.Excel.XlFindLookIn.xlValues, Microsoft.Office.Interop.Excel.XlLookAt.xlPart,
Microsoft.Office.Interop.Excel.XlSearchOrder.xlByRows, Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, false,
Type.Missing, Type.Missing);
//But if I give full text to find it works fine
objRange = objExcelSheet.Cells.Find((char)(171) + "Name" + (char)(187));
有人知道吗,我如何通过给出部分文本来搜索单元格