110,535
社区成员
发帖
与我相关
我的任务
分享
string path = string.Format(@"{0}\", this.textBox1.Text);
if (File.Exists(path + "samples.xls"))
{
}
else
{
StreamWriter test = new StreamWriter(path + "samples.xls", true);
}
if (IsFirstLoad == true)
{
Workbooks wbks = excel.Workbooks; //创建工作簿
_Workbook _wbk = wbks.Open(path + "samples.xls");//打开Excel
excel.DisplayAlerts = true;
Sheets shs = _wbk.Sheets;
Worksheet _wsh = (Worksheet)shs.get_Item(1);//取得Sheet
excel.Visible = true;
string cell1 = this.textBox5.Text.Trim(); ;
string cell2 = this.textBox6.Text.Trim();
string cell3 = this.textBox10.Text.Trim();
string c1 = cell1.Substring(0, 1);
int c11 = Convert.ToInt32(cell1.Substring(1));
if (this.textBox5.Text != null && this.textBox5.Text.Trim() != "")
{
for (int r = 1; r <= dataGridView1.Rows.Count; r++)
{
Microsoft.Office.Interop.Excel.Range cel = _wsh.get_Range(c1 + c11++);
cel.Value2 = dataGridView1.Rows[r - 1].Cells[2].Value.ToString();
}
}
if (this.textBox6.Text.Trim() != null && this.textBox6.Text.Trim() != "")
{
for (int r = 0; r < dataGridView1.Rows.Count; r++)
{
Microsoft.Office.Interop.Excel.Range cel = _wsh.get_Range(c1 + c11++);
excel.Cells[r + 1, 2] = dataGridView1.Rows[r].Cells[3].Value.ToString();
}
}
if (this.textBox10.Text.Trim() != null && this.textBox10.Text.Trim() != "")
{
for (int r = 0; r < dataGridView1.Rows.Count; r++)
{
Microsoft.Office.Interop.Excel.Range cel = _wsh.get_Range(c1 + c11++);
excel.Cells[r + 1, 3] = dataGridView1.Rows[r].Cells[4].Value.ToString();
}
}
IsFirstLoad = true;
}
else
{
Workbooks wbks = excel.Workbooks; //创建工作簿
excel.DisplayAlerts = false;
_Workbook _wbk = wbks.Open(path + "samples.xls");//打开Excel
excel.DisplayAlerts = true;
Sheets shs = _wbk.Sheets;
Worksheet _wsh = (Worksheet)shs.get_Item(1);//取得Sheet
excel.Visible = true;
string cell1 = this.textBox5.Text.Trim(); ;
string cell2 = this.textBox6.Text.Trim();
string cell3 = this.textBox10.Text.Trim();
string c1 = cell1.Substring(0, 1);
int c11 = Convert.ToInt32(cell1.Substring(1));
if (this.textBox5.Text != null && this.textBox5.Text.Trim() != "")
{
for (int r = 1; r <= dataGridView1.Rows.Count; r++)
{
Microsoft.Office.Interop.Excel.Range cel = _wsh.get_Range(c1 + c11++);
cel.Value2 = dataGridView1.Rows[r - 1].Cells[2].Value.ToString();
}
}
if (this.textBox6.Text.Trim() != null && this.textBox6.Text.Trim() != "")
{
for (int r = 0; r < dataGridView1.Rows.Count; r++)
{
Microsoft.Office.Interop.Excel.Range cel = _wsh.get_Range(c1 + c11++);
excel.Cells[r + 1, 2] = dataGridView1.Rows[r].Cells[3].Value.ToString();
}
}
if (this.textBox10.Text.Trim() != null && this.textBox10.Text.Trim() != "")
{
for (int r = 0; r < dataGridView1.Rows.Count; r++)
{
Microsoft.Office.Interop.Excel.Range cel = _wsh.get_Range(c1 + c11++);
excel.Cells[r + 1, 3] = dataGridView1.Rows[r].Cells[4].Value.ToString();
}
}
IsFirstLoad = true;
}