Excel レポートを生成するための Office.Interop.Excel。
Microsoft.Office.Interop.Excel オブジェクトを使用してテキストを読み込んで置き換える事前定義された Excel テンプレートがあります。私の問題は、テキストの一部を使用してExcelシートのセルを検索すると機能しないことですが、私の古いVB 6コードでは正常に機能します私のコードはVB6で機能し、c#.4では機能していません
検索する必要がある Excel シートのセル
行 "2" 、列 "D" にテキスト "«Name»" が含まれています
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));
テキストの一部を指定してセルを検索するにはどうすればよいですか