C# Excel中的range.find方法
我有一个带有标题的Excel文件C# Excel中的range.find方法,c#,C#,我有一个带有标题的Excel文件 Sep-08 Oct-08 Nov-08 Dec-08 Jan-09 Feb-09 Mar-09 Apr-09 我想传递一个字符串,比如说Dec-08,然后得到单元格的地址,这个地址在一个范围内 Iam正在使用range.find方法,但无法在Excel中找到日期。非常感谢您的帮助//全局声明这两个变量,以便您可以从这两个变量访问它们 //按钮1和按钮2。 Excel.applicationobjapp; Excel.\u工作簿 privat
Sep-08 Oct-08 Nov-08 Dec-08 Jan-09 Feb-09 Mar-09 Apr-09
我想传递一个字符串,比如说Dec-08,然后得到单元格的地址,这个地址在一个范围内
Iam正在使用range.find方法,但无法在Excel中找到日期。非常感谢您的帮助//全局声明这两个变量,以便您可以从这两个变量访问它们 //按钮1和按钮2。 Excel.applicationobjapp; Excel.\u工作簿
private void button1_Click(object sender, System.EventArgs e)
{
Excel.Workbooks objBooks;
Excel.Sheets objSheets;
Excel._Worksheet objSheet;
Excel.Range range;
try
{
// Instantiate Excel and start a new workbook.
objApp = new Excel.Application();
objBooks = objApp.Workbooks;
objBook = objBooks.Add( Missing.Value );
objSheets = objBook.Worksheets;
objSheet = (Excel._Worksheet)objSheets.get_Item(1);
//Get the range where the starting cell has the address
//m_sStartingCell and its dimensions are m_iNumRows x m_iNumCols.
range = objSheet.get_Range("A1", Missing.Value);
range = range.get_Resize(5, 5);
if (this.FillWithStrings.Checked == false)
{
//Create an array.
double[,] saRet = new double[5, 5];
//Fill the array.
for (long iRow = 0; iRow < 5; iRow++)
{
for (long iCol = 0; iCol < 5; iCol++)
{
//Put a counter in the cell.
saRet[iRow, iCol] = iRow * iCol;
}
}
//Set the range value to the array.
range.set_Value(Missing.Value, saRet );
}
else
{
//Create an array.
string[,] saRet = new string[5, 5];
//Fill the array.
for (long iRow = 0; iRow < 5; iRow++)
{
for (long iCol = 0; iCol < 5; iCol++)
{
//Put the row and column address in the cell.
saRet[iRow, iCol] = iRow.ToString() + "|" + iCol.ToString();
}
}
//Set the range value to the array.
range.set_Value(Missing.Value, saRet );
}
//Return control of Excel to the user.
objApp.Visible = true;
objApp.UserControl = true;
}
catch( Exception theException )
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat( errorMessage, theException.Message );
errorMessage = String.Concat( errorMessage, " Line: " );
errorMessage = String.Concat( errorMessage, theException.Source );
MessageBox.Show( errorMessage, "Error" );
}
}
好像是你昨天的问题的翻版:我还没有得到答案。。这就是为什么我用不同的方式来构建它