VBAプロシージャをC#プロジェクトに移植しています。私はすべてが終わったばかりだが、2つのエラーが残っている。これは、構文は次のとおりです。C#Excel検索機能の使用
あなたの最初のエラーのためにpublic static void ExcelPort()
{
object What = "*";
object After = xlWorkSheet.get_Range("A1", "IV65536");
object LookIn = Excel.XlFindLookIn.xlValues;
object LookAt = Excel.XlLookAt.xlPart;
object SearchOrder = Excel.XlSearchOrder.xlByRows;
Excel.XlSearchDirection SearchDirection = Excel.XlSearchDirection.xlNext;
object MatchCase = System.Reflection.Missing.Value;
object MatchByte = System.Reflection.Missing.Value;
object SearchFormat = System.Reflection.Missing.Value;
currentsheet = (Excel._Worksheet)(xlWorkBook.ActiveSheet);
activeworkbook = (Excel.Workbook)xlApp.ActiveWorkbook;
int lastrow = 0;
foreach (Excel.Worksheet sheet in activeworkbook.Worksheets)
{
if (usedrows = (double)xlApp.WorksheetFunction.CountA(sheet.Cells) != 0)
{
lastrow = sheet.Cells.Find(What,After,LookIn,LookAt,SearchOrder,SearchDirection,MatchCase,MatchByte,SearchFormat);
}
else
{
lastrow = 1;
}
}
}
エラー一覧&行
//This line throws an error
(double)xlApp.WorksheetFunction.CountA(sheet.Cells) != 0
//Error:
Cannot implicitly convert type 'bool' to 'double'
//This line throws an error sheet.Cells.Find(What,After,LookIn,LookAt,SearchOrder,SearchDirection,MatchCase,MatchByte,SearchFormat)
//Error:
Cannot implicitly convert type 'Microsoft.Office.Interop.Excel.Range' to 'int'
@stuartd - 私は場合に行を変更した場合(usedrowsの=(ダブル)( xlApp.WorksheetFunction.CountA(sheet.Cells))!= 0)私はまだ同じエラーを受け取ります。 –
@stuartd - double usedrows; –
Find()は、一致するセル(存在する場合)への参照を返します。一致しない場合はNothing/Nullを返します。 'lastrow = sheet.Cells.Find(...)。Row'はおそらくあなたがここで欲しいものです。 –