【发布时间】:2017-11-09 00:04:37
【问题描述】:
我在做一个 c# windows 应用程序项目。它将读取所有 excel 标题并粘贴到 checkListBox。在checkedListBox的选定项目之后。它将从 excel 中删除列标题和行(例如单击 excel 的标题列并按删除按钮)
你能帮我吗:'(
public void OpenFile()
{
Excel excel = new Excel(@"D:\Book2.xlsx", 1);
for(int i = 0; i <= 4; i++)
{
label1.Text = "Total : " + i.ToString() + " Column";
label2.Text = excel.ReadCell(0, i);
checkedListBox1.Items.Insert(i, label2.Text);
}
}
class Excel
{
string path = "";
_Application excel = new _Excel.Application();
Workbook wb;
Worksheet ws;
public Excel(string path, int Sheet)
{
this.path = path;
wb = excel.Workbooks.Open(path);
ws = wb.Worksheets[Sheet];
}
public string ReadCell(int i, int j)
{
i++;
j++;
if(ws.Cells[i, j].Value2 != null)
{
return ws.Cells[i, j].Value2;
}
else
{
return "";
}
}
}
【问题讨论】:
-
各位,这不是自动化问题。
标签: c# excel winforms windows-applications worksheet