gvar.gintDGRow = 0;
gvar.gintOrd = 0;
string[,] strCanvass = new string[99999, 13];
string strLastRow;
Excel2.Application oXL;
Excel2._Workbook oWB;
Excel2._Worksheet oSheet;
Excel2.Range oRng;
for (int i = 0; i < DataGridView1.RowCount - 1; i++)
{
if (DataGridView1.Rows[gvar.gintDGRow].Cells[0].Value.ToString() != "")
{
strCanvass[gvar.gintDGRow, 0] = DataGridView1.Rows[gvar.gintDGRow].Cells[0].Value.ToString();
strCanvass[gvar.gintDGRow, 1] = DataGridView1.Rows[gvar.gintDGRow].Cells[1].Value.ToString();
strCanvass[gvar.gintDGRow, 2] = DataGridView1.Rows[gvar.gintDGRow].Cells[2].Value.ToString();
strCanvass[gvar.gintDGRow, 3] = DataGridView1.Rows[gvar.gintDGRow].Cells[3].Value.ToString();
strCanvass[gvar.gintDGRow, 4] = DataGridView1.Rows[gvar.gintDGRow].Cells[4].Value.ToString();
strCanvass[gvar.gintDGRow, 5] = DataGridView1.Rows[gvar.gintDGRow].Cells[5].Value.ToString();
strCanvass[gvar.gintDGRow, 6] = DataGridView1.Rows[gvar.gintDGRow].Cells[6].Value.ToString();
strCanvass[gvar.gintDGRow, 7] = DataGridView1.Rows[gvar.gintDGRow].Cells[8].Value.ToString();
strCanvass[gvar.gintDGRow, 8] = DataGridView1.Rows[gvar.gintDGRow].Cells[9].Value.ToString();
strCanvass[gvar.gintDGRow, 9] = DataGridView1.Rows[gvar.gintDGRow].Cells[10].Value.ToString();
strCanvass[gvar.gintDGRow, 10] = DataGridView1.Rows[gvar.gintDGRow].Cells[11].Value.ToString();
strCanvass[gvar.gintDGRow, 11] = DataGridView1.Rows[gvar.gintDGRow].Cells[12].Value.ToString();
}
gvar.gintDGRow++;
}
strLastRow = "L" + Convert.ToString(gvar.gintDGRow +1 );
oXL = new Excel2.Application();
oXL.Visible = true;
//Get a new workbook.
oWB = (Excel2._Workbook)(oXL.Workbooks.Add(Missing.Value));
oSheet = (Excel2._Worksheet)oWB.ActiveSheet;
//Add table headers going cell by cell.
oSheet.Cells[1, 1] = "RR Date";
oSheet.Cells[1, 2] = "RR No.";
oSheet.Cells[1, 3] = "DR/SI";
oSheet.Cells[1, 4] = "P.O. No.";
oSheet.Cells[1, 5] = "Vendor ID";
oSheet.Cells[1, 6] = "Vendor Name";
oSheet.Cells[1, 7] = "Van No.";
oSheet.Cells[1, 8] = "Item Code";
oSheet.Cells[1, 9] = "Description";
oSheet.Cells[1, 10] = "U of M.";
oSheet.Cells[1, 11] = "Qty Recv.";
oSheet.Cells[1, 12] = "Unit Cost";
oSheet.get_Range("A1", "L1").Font.Bold = true;
oSheet.get_Range("A1", "L1").VerticalAlignment =
Excel2.XlVAlign.xlVAlignCenter;
// Create an array to multiple values at once.
for (int x = 0; x < strCanvass.Length; x++)
{
Convert.ToDecimal(strCanvass[x, 11]);
oSheet.get_Range("A2", strLastRow).Value2 = strCanvass;
}
oXL.Visible = true;
oXL.UserControl = true;
我有一个数据网格列表,其中有 12 列插入到我创建的数组中,并调用了该数组以将数据导出到 excel,只有 11 列需要转换为十进制才能进行汇总。我尝试转换它,但它没有在 excel 上求和以便求和,它需要在右侧才能求和,但是当我导出它时,它在左侧无法求和。谁能帮我解决这个问题我不太明白对不起..