0
我試圖從'行標籤' (F列) 我需要從列F列表中的Row_Items列表(在事件庫姆)
private void Submit_Click(object sender, EventArgs e)
{
Procsslabel.Visible = true;
Incident_Path = Incident_AnalysistextBox.Text.Trim();
Excel.Application xlApp ;
Excel.Workbook xlWorkBook ;
Excel.Worksheet xlWorkSheet ;
Excel.Range range ;
string str;
int rCnt = 0;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(Incident_Path, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item("Ageing");
range = xlWorkSheet.UsedRange;
for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{
string str1 = (string)(range.Cells[rCnt, 1] as Excel.Range).Value2;
if(str1=="Row Labels")
{
for (rCnt = rCnt+1; rCnt < range.Rows.Count; rCnt++)
{
str = (string)(range.Cells[rCnt, 1] as Excel.Range).Value2;
List<string> Row_Items = new List<string>();
Row_Items.Add(str);//Adding items to this list
MessageBox.Show(str);
}
break;
}
}
//string cellName;// Here i want write the data into my excel sheet under F column
//int counter=1;
//foreach (var item in Row_Items)// Here i am getting error that Row_Items does not exist in this context
// {
//cellName = "F" + counter.ToString();
//range = sheet.get_Range(cellName, cellName);
//range.Value2 = item.ToString();
//++counter;
//}
xlWorkBook.Close(true, null, null);
xlApp.Quit();
Procsslabel.Visible= false;
MessageBox.Show("The Ageing Report has been successfully updated");
}