本文整理汇总了C#中Excel.Application.get_Range方法的典型用法代码示例。如果您正苦于以下问题:C# Excel.Application.get_Range方法的具体用法?C# Excel.Application.get_Range怎么用?C# Excel.Application.get_Range使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Excel.Application
的用法示例。
在下文中一共展示了Excel.Application.get_Range方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EXCEL_HZ
private void EXCEL_HZ(string name, string date)
{
Excel.Application excel = new Excel.Application();
excel.Application.Workbooks.Add(true);
excel.Visible = true;
excel.get_Range("A1", "j2").Merge(false);
excel.get_Range("A3", "j3").Merge(false);
excel.get_Range("A4", "A5").Merge(false);
excel.get_Range("B4", "B5").Merge(false);
excel.get_Range("C4", "C5").Merge(false);
excel.get_Range("J4", "J5").Merge(false);
excel.get_Range("D4", "E4").Merge(false);
excel.get_Range("F4", "G4").Merge(false);
excel.get_Range("H4", "I4").Merge(false);
excel.get_Range("A6", "A8").Merge(false);
excel.get_Range("B6", "B8").Merge(false);
//excel.get_Range("C6", "C8").Merge(false);
excel.get_Range("J6", "J8").Merge(false);
excel.get_Range("A9", "A11").Merge(false);
excel.get_Range("B9", "B11").Merge(false);
excel.get_Range("J9", "J11").Merge(false);
//excel.get_Range("C9", "C11").Merge(false);
excel.get_Range("A12", "A14").Merge(false);
excel.get_Range("B12", "B14").Merge(false);
excel.get_Range("J12", "J14").Merge(false);
//excel.get_Range("C12", "C14").Merge(false);
excel.get_Range("A15", "A17").Merge(false);
excel.get_Range("B15", "B17").Merge(false);
excel.get_Range("J15", "J17").Merge(false);
//excel.get_Range("C15", "C17").Merge(false);
excel.get_Range("A18", "A20").Merge(false);
excel.get_Range("B18", "B20").Merge(false);
excel.get_Range("J18", "J20").Merge(false);
//excel.get_Range("C18", "C20").Merge(false);
excel.get_Range("A21", "A23").Merge(false);
excel.get_Range("B21", "B23").Merge(false);
excel.get_Range("J21", "J23").Merge(false);
//excel.get_Range("C21", "C23").Merge(false);
excel.get_Range("A24", "A26").Merge(false);
excel.get_Range("B24", "B26").Merge(false);
excel.get_Range("J24", "J26").Merge(false);
//excel.get_Range("C24", "C26").Merge(false);
excel.get_Range("A27", "A29").Merge(false);
excel.get_Range("B27", "B29").Merge(false);
excel.get_Range("J27", "J29").Merge(false);
//excel.get_Range("C27", "C29").Merge(false);
excel.get_Range("A30", "A32").Merge(false);
excel.get_Range("B30", "B32").Merge(false);
excel.get_Range("J30", "J32").Merge(false);
//excel.get_Range("C30", "C32").Merge(false);
excel.get_Range("A33", "A35").Merge(false);
excel.get_Range("B33", "B35").Merge(false);
excel.get_Range("J33", "J35").Merge(false);
//excel.get_Range("C33", "C35").Merge(false);
excel.get_Range("A36", "A38").Merge(false);
excel.get_Range("B36", "B38").Merge(false);
excel.get_Range("J36", "J38").Merge(false);
//excel.get_Range("C36", "C38").Merge(false);
excel.get_Range("A1", "A1").Value = name;
excel.get_Range("A3", "A3").Value = date;
excel.get_Range("A4", "A4").Value = "序号";
excel.get_Range("B4", "B4").Value = "公司";
excel.get_Range("J4", "J4").Value = "备注";
excel.get_Range("C4", "C4").Value = "来源";
excel.get_Range("D4", "D4").Value = "本年";
excel.get_Range("F4", "F4").Value = "同期";
excel.get_Range("H4", "H4").Value = "增减额";
excel.get_Range("D5", "D5").Value = "本月";
excel.get_Range("E5", "E5").Value = "累计";
excel.get_Range("F5", "F5").Value = "本月";
excel.get_Range("G5", "G5").Value = "累计";
excel.get_Range("H5", "H5").Value = "本月";
excel.get_Range("I5", "I5").Value = "累计";
//excel.get_Range("A6", "A6").Value = "";
//excel.get_Range("B6", "B6").Value = "沈阳铸锻工业有限公司";
//excel.get_Range("C6", "C6").Value = "内部";
//excel.get_Range("C7", "C7").Value = "外部";
//excel.get_Range("C8", "C8").Value = "小计";
//excel.get_Range("A9", "A9").Value = "1";
//excel.get_Range("B9", "B9").Value = "沈阳铸锻工业有限公司本部公司";
//excel.get_Range("C9", "C9").Value = "内部";
//excel.get_Range("C10", "C10").Value = "外部";
//excel.get_Range("C11", "C11").Value = "小计";
//excel.get_Range("A12", "A12").Value = "2";
//excel.get_Range("B12", "B12").Value = "沈阳铸锻工业有限公司铸钢公司";
//excel.get_Range("C12", "C12").Value = "内部";
//excel.get_Range("C13", "C13").Value = "外部";
//excel.get_Range("C14", "C14").Value = "小计";
//excel.get_Range("A15", "A15").Value = "3";
//excel.get_Range("B15", "B15").Value = "沈阳铸锻工业有限公司锻造公司";
//excel.get_Range("C15", "C15").Value = "内部";
//excel.get_Range("C16", "C16").Value = "外部";
//excel.get_Range("C17", "C17").Value = "小计";
//.........这里部分代码省略.........
示例2: EXCEL_FKMX
private void EXCEL_FKMX()
{
Excel.Application excel = new Excel.Application();
excel.Application.Workbooks.Add(true);
excel.Visible = true;
excel.get_Range("A1", excel.Cells[2, dataGridView1.Columns.Count]).Merge(false);
excel.get_Range("A3", excel.Cells[3, dataGridView1.Columns.Count]).Merge(false);
excel.get_Range("A4", "A6").Merge(false);
excel.get_Range("B4", "c6").Merge(false);
excel.get_Range("D4", "G4").Merge(false);
excel.get_Range("H4", "K4").Merge(false);
excel.get_Range("L4", "M4").Merge(false);
excel.get_Range("N4", "Q4").Merge(false);
excel.get_Range("R4", "S4").Merge(false);
excel.get_Range("E5", "F5").Merge(false);
excel.get_Range("I5", "J5").Merge(false);
excel.get_Range("O5", "P5").Merge(false);
excel.get_Range("D5", "D6").Merge(false);
excel.get_Range("G5", "G6").Merge(false);
excel.get_Range("H5", "H6").Merge(false);
excel.get_Range("K5", "K6").Merge(false);
excel.get_Range("L5", "L6").Merge(false);
excel.get_Range("M5", "M6").Merge(false);
excel.get_Range("N5", "N6").Merge(false);
excel.get_Range("Q5", "Q6").Merge(false);
excel.get_Range("R5", "R6").Merge(false);
excel.get_Range("S5", "S6").Merge(false);
excel.get_Range("T4", "T6").Merge(false);
excel.get_Range("A" + (this.dataGridView1.Rows.Count + 4).ToString(), "B" + (this.dataGridView1.Rows.Count + 6).ToString()).Merge(false);
//(excel.Cells[1, 1] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
//(excel.Cells[3, 1] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
excel.get_Range("A1", "T6").HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
excel.get_Range("A3", "A3").HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
//(excel.Cells[5, "m"] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
//(excel.Cells[5, "g"] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
excel.get_Range("A1", "t6").Font.Bold = true;
excel.Cells[4, "A"] = "序号";
excel.Cells[4, "B"] = "合同种类";
excel.get_Range("A4", "A6").Value = "序号";
excel.get_Range("B4", "c6").Value = "公司名称";
excel.get_Range("D4", "G4").Value = "合同总额";
excel.get_Range("H4", "K4").Value = (this.toolStripComboBox4.Text == "0201:产品销售" ? "已收货款" : "已付货款");
excel.get_Range("L4", "M4").Value = (this.toolStripComboBox4.Text == "0201:产品销售" ? "未收货款" : "未付货款");
excel.get_Range("N4", "Q4").Value = (this.toolStripComboBox4.Text == "0201:产品销售" ? "已开发票金额" : "已收发票金额");
excel.get_Range("R4", "S4").Value = (this.toolStripComboBox4.Text == "0201:产品销售" ? "未开票金额" : "未收票金额");
excel.get_Range("E5", "F5").Value = "本年";
excel.get_Range("I5", "J5").Value = "本年";
excel.get_Range("O5", "P5").Value = "本年";
excel.get_Range("D5", "D6").Value = "以前年度";
excel.get_Range("G5", "G6").Value = "总累计";
excel.get_Range("H5", "H6").Value = "以前年度";
excel.get_Range("K5", "K6").Value = "总累计";
excel.get_Range("L5", "L6").Value = "金额";
excel.get_Range("M5", "M6").Value = "比例";
excel.get_Range("N5", "N6").Value = "以前年度";
excel.get_Range("Q5", "Q6").Value = "总累计";
excel.get_Range("R5", "R6").Value = "金额";
excel.get_Range("S5", "S6").Value = "比例";
excel.get_Range("T4", "T6").Value = "备注";
excel.get_Range("E6", "E6").Value = "本月";
excel.get_Range("F6", "F6").Value = "本年";
excel.get_Range("I6", "I6").Value = "本月";
excel.get_Range("J6", "J6").Value = "本年";
excel.get_Range("O6", "O6").Value = "本月";
excel.get_Range("P6", "P6").Value = "本年";
excel.get_Range("A" + (this.dataGridView1.Rows.Count + 4).ToString(), "B" + (this.dataGridView1.Rows.Count + 4).ToString()).Value = "总计";
excel.get_Range("c" + (this.dataGridView1.Rows.Count + 4).ToString(), "c" + (this.dataGridView1.Rows.Count + 4).ToString()).Value = "外部";
excel.get_Range("c" + (this.dataGridView1.Rows.Count + 5).ToString(), "c" + (this.dataGridView1.Rows.Count + 5).ToString()).Value = "内部";
excel.get_Range("c" + (this.dataGridView1.Rows.Count + 6).ToString(), "c" + (this.dataGridView1.Rows.Count + 6).ToString()).Value = "合计";
excel.get_Range("a1", "t2").Value = ClassCustom.codeSub1(this.toolStripComboBox4.Text) + "合同总览表";
excel.get_Range("a3", "a3").Value = this.toolStripComboBox4.Text + " " + this.toolStripComboBox1.Text + "年" + this.toolStripComboBox2.Text + "月";
//DataTable dt = DBAdo.DtFillSql("SELECT LID,LNAME FROM ALX WHERE LID LIKE '" + ClassCustom.codeSub(this.toolStripComboBox4.Text) + "__'");
string str = ClassCustom.codeSub(this.toolStripComboBox4.Text);
DataTable dt = DBAdo.DtFillSql("SELECT CCODE,CNAME FROM ACLIENTS WHERE CCODE LIKE '01__'");
int index = 0;
for (int i = 0; i < dt.Rows.Count * 2; i++)
{
excel.get_Range("B" + (i + 7).ToString(), "B" + (i + 8).ToString()).Merge(false);
excel.get_Range("B" + (i + 7).ToString(), "B" + (i + 8).ToString()).Value = dt.Rows[index][1].ToString();
excel.get_Range("A" + (i + 7).ToString(), "A" + (i + 8).ToString()).Merge(false);
excel.get_Range("A" + (i + 7).ToString(), "A" + (i + 8).ToString()).Value = (index + 1).ToString();
excel.get_Range("C" + (i + 7).ToString(), "C" + (i + 7).ToString()).Value = "外部";
excel.get_Range("C" + (i + 8).ToString(), "C" + (i + 8).ToString()).Value = "内部";
index++;
i++;
}
excel.get_Range("d7", excel.Cells[dataGridView1.Rows.Count + 6, "t"]).NumberFormat = "#,##0.00";
excel.get_Range("m7", excel.Cells[dataGridView1.Rows.Count + 6, "m"]).NumberFormat = "0%";
excel.get_Range("s7", excel.Cells[dataGridView1.Rows.Count + 6, "s"]).NumberFormat = "0%";
//填充数据
for (int i = 0; i < dataGridView1.RowCount; i++)
{
for (int j = 3; j < dataGridView1.ColumnCount; j++)
{
if (dataGridView1[j, i].ValueType == typeof(string))
{
//.........这里部分代码省略.........
示例3: EXCEL_FKMX
/// <summary>
/// 付款情况明细表导出EXCEL
/// </summary>
/// <param name="name">表头</param>
/// <param name="dw">分公司名</param>
/// <param name="date">年月</param>
private void EXCEL_FKMX(string name, string dw, string date)
{
Excel.Application excel = new Excel.Application();
excel.Application.Workbooks.Add(true);
excel.Visible = true;
excel.get_Range("A1", excel.Cells[2, dataGridView1.Columns.Count]).Merge(false);
excel.get_Range("A3", excel.Cells[3, dataGridView1.Columns.Count]).Merge(false);
excel.get_Range("A4", "A6").Merge(false);
excel.get_Range("B4", "B6").Merge(false);
excel.get_Range("C4", "C6").Merge(false);
excel.get_Range("D4", "D6").Merge(false);
excel.get_Range("E4", "E6").Merge(false);
excel.get_Range("F4", "I4").Merge(false);
excel.get_Range("J4", "K4").Merge(false);
excel.get_Range("L4", "O4").Merge(false);
excel.get_Range("P4", "Q4").Merge(false);
excel.get_Range("R4", "R6").Merge(false);
excel.get_Range("S4", "S6").Merge(false);
excel.get_Range("G5", "H5").Merge(false);
excel.get_Range("M5", "N5").Merge(false);
excel.get_Range("F5", "F6").Merge(false);
excel.get_Range("I5", "I6").Merge(false);
excel.get_Range("J5", "J6").Merge(false);
excel.get_Range("K5", "K6").Merge(false);
excel.get_Range("P5", "P6").Merge(false);
excel.get_Range("L5", "L6").Merge(false);
excel.get_Range("O5", "O6").Merge(false);
excel.get_Range("P5", "P6").Merge(false);
excel.get_Range("Q5", "Q6").Merge(false);
excel.Cells[1, 1] = name;
excel.Cells[3, 1] = dw + " " + date;
(excel.Cells[1, 1] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
(excel.Cells[3, 1] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
excel.get_Range("A4", "S4").HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
//(excel.Cells[5, "m"] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
//(excel.Cells[5, "g"] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
excel.get_Range("A1", "S6").Font.Bold = true;
excel.Cells[4, "A"] = "序号";
excel.Cells[4, "B"] = "内外";
excel.Cells[4, "C"] = "合同号";
excel.Cells[4, "D"] = "客户";
excel.Cells[4, "E"] = "结算金额";
excel.Cells[4, "F"] = "已付货款";
excel.Cells[4, "J"] = "未付货款";
excel.Cells[4, "L"] = "已收发票金额";
excel.Cells[4, "P"] = "未收发票金额";
excel.Cells[4, "R"] = "财务余额";
excel.Cells[4, "S"] = "备注";
excel.Cells[5, "G"] = "本年";
excel.Cells[5, "M"] = "本年";
excel.Cells[6, "M"] = "本月";
excel.Cells[6, "G"] = "本月";
excel.Cells[5, "F"] = "上年";
excel.Cells[5, "L"] = "上年";
excel.Cells[5, "I"] = "总累计";
excel.Cells[5, "O"] = "总累计";
excel.Cells[5, "J"] = "金额";
excel.Cells[5, "P"] = "金额";
excel.Cells[5, "K"] = "比例";
excel.Cells[5, "Q"] = "比例";
excel.Cells[6, "G"] = "本月";
excel.Cells[6, "M"] = "本月";
excel.Cells[6, "H"] = "本年";
excel.Cells[6, "N"] = "本年";
excel.get_Range("E7", excel.Cells[dataGridView1.Rows.Count + 6, "R"]).NumberFormat = "#,##0.00";
excel.get_Range("k7", excel.Cells[dataGridView1.Rows.Count + 6, "k"]).NumberFormat = "0%";
excel.get_Range("q7", excel.Cells[dataGridView1.Rows.Count + 6, "q"]).NumberFormat = "0%";
//填充数据
for (int i = 0; i < dataGridView1.RowCount; i++)
{
for (int j = 0; j < dataGridView1.ColumnCount; j++)
{
if (dataGridView1[j, i].ValueType == typeof(string))
{
excel.Cells[i + 7, j + 1] = "'" + dataGridView1[j, i].Value.ToString();
}
else
{
excel.Cells[i + 7, j + 1] = dataGridView1[j, i].Value.ToString();
}
}
}
excel.get_Range("A1", excel.Cells[dataGridView1.Rows.Count + 6, dataGridView1.Columns.Count]).EntireColumn.AutoFit();
ClassCustom.DrawExcelBorders(excel, "A4", excel.Cells[dataGridView1.Rows.Count + 6, dataGridView1.Columns.Count]);
Excel.Worksheet sheet1 = excel.Worksheets[1] as Excel.Worksheet;
sheet1.PageSetup.PrintTitleRows = "$1:$6";
//sheet1.PageSetup.PaperSize = Excel.XlPaperSize.xlPaperFanfoldUS;
}
示例4: EXCEL_ML
private void EXCEL_ML(string date, string dw)
{
Excel.Application excel = new Excel.Application();
excel.Application.Workbooks.Add(true);
excel.Visible = true;
excel.get_Range("A1", excel.Cells[2, dataGridView1.Columns.Count]).Merge(false);
excel.get_Range("A3", excel.Cells[3, dataGridView1.Columns.Count]).Merge(false);
excel.get_Range("A4", "A5").Merge(false);
excel.get_Range("B4", "B5").Merge(false);
excel.get_Range("C4", "C5").Merge(false);
excel.get_Range("D4", "D5").Merge(false);
excel.get_Range("E4", "E5").Merge(false);
//excel.get_Range("F4", "I4").Merge(false);
excel.get_Range("l4", "l5").Merge(false);
excel.get_Range("m4", "m5").Merge(false);
excel.get_Range("n4", "n5").Merge(false);
excel.get_Range("f4", "h4").Merge(false);
excel.get_Range("i4", "k4").Merge(false);
excel.Cells[1, 1] = "销售合同毛利明细表";
excel.Cells[3, 1] = dw + " " + date;
(excel.Cells[1, 1] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
(excel.Cells[3, 1] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
excel.get_Range("A4", "m5").HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
excel.get_Range("A1", "S5").Font.Bold = true;
excel.Cells[4, "A"] = "部门";
excel.Cells[4, "B"] = "签订日期";
excel.Cells[4, "C"] = "客户类型";
excel.Cells[4, "D"] = "合同号";
excel.Cells[4, "E"] = "客户";
excel.Cells[4, "F"] = "销售合同总额";
excel.Cells[4, "i"] = "外协合同总额";
excel.Cells[5, "f"] = "收入";
excel.Cells[5, "g"] = "税额";
excel.Cells[5, "h"] = "小计";
excel.Cells[5, "i"] = "成本";
excel.Cells[5, "j"] = "税额";
excel.Cells[5, "k"] = "小计";
excel.Cells[4, "l"] = "产品毛利";
excel.Cells[4, "m"] = "比率";
excel.Cells[4, "n"] = "备注";
excel.get_Range("F6", excel.Cells[dataGridView1.Rows.Count + 5, "M"]).NumberFormat = "#,##0.00";
excel.get_Range("M6", excel.Cells[dataGridView1.Rows.Count + 5, "M"]).NumberFormat = "0%";
//填充数据
for (int i = 0; i < dataGridView1.RowCount; i++)
{
for (int j = 0; j < dataGridView1.ColumnCount; j++)
{
if (dataGridView1[j, i].ValueType == typeof(string))
{
excel.Cells[i + 6, j + 1] = "'" + dataGridView1[j, i].Value.ToString();
}
else
{
excel.Cells[i + 6, j + 1] = dataGridView1[j, i].Value.ToString();
}
}
}
excel.get_Range("A1", excel.Cells[dataGridView1.Rows.Count + 5, dataGridView1.Columns.Count]).EntireColumn.AutoFit();
ClassCustom.DrawExcelBorders(excel, "A4", excel.Cells[dataGridView1.Rows.Count + 5, dataGridView1.Columns.Count]);
Excel.Worksheet sheet1 = excel.Worksheets[1] as Excel.Worksheet;
sheet1.PageSetup.PrintTitleRows = "$1:$5";
//sheet1.PageSetup.PaperSize = Excel.XlPaperSize.xlPaperFanfoldUS;
}
示例5: EXCEL_BB_SK_HZ
/// <summary>
/// 付款情况汇总表导出EXCEL
/// </summary>
/// <param name="name">表头</param>
/// <param name="dw">分公司名</param>
/// <param name="date">年月</param>
private void EXCEL_BB_SK_HZ(string name, string dw, string date)
{
//MessageBox.Show("Test");
Excel.Application excel = new Excel.Application();
excel.Application.Workbooks.Add(true);
excel.Visible = true;
excel.get_Range("A1", excel.Cells[2, dataGridView1.Columns.Count]).Merge(false);
excel.get_Range("A3", excel.Cells[3, dataGridView1.Columns.Count]).Merge(false);
excel.get_Range("A4", "A6").Merge(false);
excel.get_Range("B4", "B6").Merge(false);
excel.get_Range("S4", "S6").Merge(false);
excel.get_Range("C4", "F4").Merge(false);
excel.get_Range("G4", "J4").Merge(false);
excel.get_Range("K4", "L4").Merge(false);
excel.get_Range("M4", "P4").Merge(false);
excel.get_Range("Q4", "R4").Merge(false);
excel.get_Range("D5", "E5").Merge(false);
excel.get_Range("H5", "I5").Merge(false);
excel.get_Range("N5", "O5").Merge(false);
//CFGJKLMPR
excel.get_Range("C5", "C6").Merge(false);
excel.get_Range("F5", "F6").Merge(false);
excel.get_Range("G5", "G6").Merge(false);
excel.get_Range("J5", "J6").Merge(false);
excel.get_Range("K5", "K6").Merge(false);
excel.get_Range("L5", "L6").Merge(false);
excel.get_Range("M5", "M6").Merge(false);
excel.get_Range("P5", "P6").Merge(false);
excel.get_Range("Q5", "Q6").Merge(false);
excel.get_Range("R5", "R6").Merge(false);
excel.Cells[1, 1] = name;
excel.Cells[3, 1] = dw + " " + date;
(excel.Cells[1, 1] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
(excel.Cells[3, 1] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
excel.get_Range("A4", "S4").HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
excel.get_Range("A1", "S6").Font.Bold = true;
excel.Cells[4, "A"] = "部门";
excel.Cells[4, "B"] = "客户类型";
excel.Cells[4, "C"] = "签定合同总额";
excel.Cells[4, "G"] = "回款金额";
excel.Cells[4, "K"] = "尚欠金额";
excel.Cells[4, "M"] = "已开发票金额";
excel.Cells[4, "Q"] = "未开发票金额";
excel.Cells[4, "S"] = "备注";
excel.Cells[5, "D"] = "本年";
excel.Cells[5, "H"] = "本年";
excel.Cells[5, "N"] = "本年";
excel.Cells[5, "C"] = "上年";
excel.Cells[5, "G"] = "上年";
excel.Cells[5, "M"] = "上年";
excel.Cells[5, "F"] = "总累计";
excel.Cells[5, "J"] = "总累计";
excel.Cells[5, "P"] = "总累计";
excel.Cells[5, "K"] = "金额";
excel.Cells[5, "Q"] = "金额";
excel.Cells[5, "L"] = "比例";
excel.Cells[5, "R"] = "比例";
excel.Cells[6, "D"] = "本月";
excel.Cells[6, "H"] = "本月";
excel.Cells[6, "N"] = "本月";
excel.Cells[6, "E"] = "本年";
excel.Cells[6, "I"] = "本年";
excel.Cells[6, "O"] = "本年";
excel.get_Range("C7", excel.Cells[dataGridView1.Rows.Count + 6, "R"]).NumberFormat = "#,##0.00";
excel.get_Range("R7", excel.Cells[dataGridView1.Rows.Count + 6, "R"]).NumberFormat = "0%";
excel.get_Range("L7", excel.Cells[dataGridView1.Rows.Count + 6, "L"]).NumberFormat = "0%";
//填充数据
for (int i = 0; i < dataGridView1.RowCount; i++)
{
for (int j = 0; j < dataGridView1.ColumnCount; j++)
{
if (dataGridView1[j, i].ValueType == typeof(string))
{
excel.Cells[i + 7, j + 1] = "'" + dataGridView1[j, i].Value.ToString();
}
else
{
excel.Cells[i + 7, j + 1] = dataGridView1[j, i].Value.ToString();
}
}
}
for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
//MessageBox.Show(excel.Cells[i + 7, "A"].ToString());
if (excel.get_Range("A" + (i + 7), "A" + (i + 7)).Value.ToString() == "")
{
excel.Cells[i + 7, "A"] = null;
//.........这里部分代码省略.........
示例6: EXCEL_EXPORT_RMB
private void EXCEL_EXPORT_RMB(string tname, string cname, string date)
{
Excel.Application excel = new Excel.Application();
excel.Application.Workbooks.Add(true);
excel.Visible = true;
//**********************************************************************************************
excel.get_Range("A1", excel.Cells[2, dataGridView1.Columns.Count]).Merge(false);
excel.get_Range("A3", excel.Cells[3, dataGridView1.Columns.Count]).Merge(false);
excel.get_Range("A4", "A5").Merge(false);
excel.get_Range("B4", "E4").Merge(false);
excel.get_Range("F4", "J4").Merge(false);
excel.get_Range("K4", "K5").Merge(false);
excel.Cells[4, "A"] = "日期";
excel.Cells[4, "B"] = "金额";
excel.Cells[4, "F"] = "凭证信息";
excel.Cells[4, "K"] = "备注";
excel.Cells[5, "B"] = "现汇";
excel.Cells[5, "C"] = "票据";
excel.Cells[5, "D"] = "抹帐";
excel.Cells[5, "E"] = "小计";
excel.Cells[5, "F"] = "连接凭证";
excel.Cells[5, "G"] = "年";
excel.Cells[5, "H"] = "月";
excel.Cells[5, "I"] = "凭证类型";
excel.Cells[5, "J"] = "凭证号";
//**********************************************************************************************
excel.Cells[1, 1] = tname;
excel.Cells[3, 1] = cname + " " + date;
(excel.Cells[1, 1] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
(excel.Cells[3, 1] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
excel.get_Range("A4", "K4").HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
//(excel.Cells[5, "m"] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
//(excel.Cells[5, "g"] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
excel.get_Range("A1", "K5").Font.Bold = true;
//excel.get_Range("E7", excel.Cells[dataGridView1.Rows.Count + 6, "R"]).NumberFormat = "#,##0.00";
//excel.get_Range("k7", excel.Cells[dataGridView1.Rows.Count + 6, "k"]).NumberFormat = "0%";
excel.get_Range("A6", excel.Cells[dataGridView1.Rows.Count + 6, "A"]).NumberFormat = "yyyy-MM-dd";
//填充数据
for (int i = 0; i < dataGridView1.RowCount; i++)
{
for (int j = 0; j < dataGridView1.ColumnCount; j++)
{
if (dataGridView1[j, i].ValueType == typeof(string))
{
excel.Cells[i + 6, j + 1] = "'" + dataGridView1[j, i].Value.ToString();
}
else
{
excel.Cells[i + 6, j + 1] = dataGridView1[j, i].Value.ToString();
}
}
}
excel.get_Range("A1", excel.Cells[dataGridView1.Rows.Count + 5, dataGridView1.Columns.Count]).EntireColumn.AutoFit();
ClassCustom.DrawExcelBorders(excel, "A4", excel.Cells[dataGridView1.Rows.Count + 5, dataGridView1.Columns.Count + 1]);
Excel.Worksheet sheet1 = excel.Worksheets[1] as Excel.Worksheet;
sheet1.PageSetup.PrintTitleRows = "$1:$6";
//sheet1.PageSetup.PaperSize = Excel.XlPaperSize.xlPaperFanfoldUS;
}
示例7: ExportDataGridview1
/// <summary>
/// DATAGIRDVIEW数据导出EXCEL
/// 例:this.ExportDataGridview1(dataGridView1, true);
/// </summary>
/// <param name="dataGridView1">要导出的DATAGIRDVIEW</param>
/// <param name="isShowExcle">是否显示导出的EXCEL</param>
/// <returns>导出成功返回TRUE失败返回FALSE</returns>
public static Excel.Application ExportDataGridview1(DataGridView dataGridView1, string name)
{
try
{
if (dataGridView1.Rows.Count == 0)
return null;
//建立Excel对象
Excel.Application excel = new Excel.Application();
excel.Application.Workbooks.Add(true);
excel.Visible = true;
excel.get_Range("A1", excel.Cells[2, dataGridView1.Columns.Count]).Merge(false);
excel.Cells[1, 1] = name;
(excel.Cells[1, 1] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
//生成字段名称
for (int i = 0; i < dataGridView1.ColumnCount; i++)
{
excel.Cells[3, i + 1] = dataGridView1.Columns[i].HeaderText;
}
//填充数据
for (int i = 0; i < dataGridView1.RowCount; i++)
{
for (int j = 0; j < dataGridView1.ColumnCount; j++)
{
if (dataGridView1[j, i].ValueType == typeof(string))
{
excel.Cells[i + 4, j + 1] = "'" + (dataGridView1[j, i].Value == null ? "" : dataGridView1[j, i].Value.ToString());
}
else
{
excel.Cells[i + 4, j + 1] = (dataGridView1[j, i].Value == null ? "" : dataGridView1[j, i].Value.ToString());
}
}
}
excel.get_Range("A1", excel.Cells[dataGridView1.Rows.Count + 3, dataGridView1.Columns.Count]).EntireColumn.AutoFit();
DrawExcelBorders(excel, "A3", excel.Cells[dataGridView1.Rows.Count + 3, dataGridView1.Columns.Count]);
return excel;
}
catch (Exception ex)
{
//MessageBox.Show(ex.ToString());
throw ex;
//return false;
}
}
示例8: EXCEL_MX
private void EXCEL_MX(string name, string dw, string date)
{
if (this.dataGridView1.Rows.Count == 0)
return;
Excel.Application excel = new Excel.Application();
excel.Application.Workbooks.Add(true);
excel.Visible = true;
excel.get_Range("A1", excel.Cells[2, dataGridView1.Columns.Count]).Merge(false);
excel.get_Range("A3", excel.Cells[3, dataGridView1.Columns.Count]).Merge(false);
excel.get_Range("A4", "A6").Merge(false);
excel.get_Range("B4", "B6").Merge(false);
excel.get_Range("C4", "C6").Merge(false);
excel.get_Range("D4", "D6").Merge(false);
excel.get_Range("i4", "i6").Merge(false);
excel.get_Range("e4", "h4").Merge(false);
excel.get_Range("f5", "g5").Merge(false);
excel.get_Range("e5", "e6").Merge(false);
excel.get_Range("h5", "h6").Merge(false);
excel.Cells[1, 1] = name;
excel.Cells[3, 1] = dw + " " + date;
(excel.Cells[1, 1] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
(excel.Cells[3, 1] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
excel.get_Range("A4", "S4").HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
//(excel.Cells[5, "m"] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
//(excel.Cells[5, "g"] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
excel.get_Range("A1", "S6").Font.Bold = true;
excel.Cells[4, "A"] = "序号";
excel.Cells[4, "B"] = "内外";
excel.Cells[4, "C"] = "合同号";
excel.Cells[4, "D"] = "客户";
excel.Cells[4, "e"] = "结算金额";
excel.Cells[4, "i"] = "备注";
excel.Cells[5, "e"] = "上年";
excel.Cells[5, "h"] = "总累计";
excel.Cells[5, "f"] = "本年";
excel.Cells[6, "f"] = "本月";
excel.Cells[6, "g"] = "本年";
excel.get_Range("E7", excel.Cells[dataGridView1.Rows.Count + 6, "h"]).NumberFormat = "#,##0.00";
//填充数据
for (int i = 0; i < dataGridView1.RowCount; i++)
{
for (int j = 0; j < dataGridView1.ColumnCount; j++)
{
if (dataGridView1[j, i].ValueType == typeof(string))
{
excel.Cells[i + 7, j + 1] = "'" + dataGridView1[j, i].Value.ToString();
}
else
{
excel.Cells[i + 7, j + 1] = dataGridView1[j, i].Value.ToString();
}
}
}
excel.get_Range("A1", excel.Cells[dataGridView1.Rows.Count + 6, dataGridView1.Columns.Count]).EntireColumn.AutoFit();
ClassCustom.DrawExcelBorders(excel, "A4", excel.Cells[dataGridView1.Rows.Count + 6, dataGridView1.Columns.Count]);
Excel.Worksheet sheet1 = excel.Worksheets[1] as Excel.Worksheet;
sheet1.PageSetup.PrintTitleRows = "$1:$6";
//sheet1.PageSetup.PaperSize = Excel.XlPaperSize.xlPaperFanfoldUS;
}
示例9: EXCEL_MX
private void EXCEL_MX(string name, string dw, string date)
{
if (this.dataGridView1.Rows.Count == 0)
return;
try
{
Excel.Application excel = new Excel.Application();
excel.Application.Workbooks.Add(true);
excel.Visible = true;
excel.get_Range("A1", excel.Cells[2, dataGridView1.Columns.Count]).Merge(false);
excel.get_Range("A3", excel.Cells[3, dataGridView1.Columns.Count]).Merge(false);
excel.get_Range("A4", "A5").Merge(false);
excel.get_Range("B4", "B5").Merge(false);
excel.get_Range("C4", "C5").Merge(false);
excel.get_Range("D4", "D5").Merge(false);
excel.get_Range("E4", "E5").Merge(false);
excel.get_Range("I4", "I5").Merge(false);
excel.get_Range("H4", "H5").Merge(false);
excel.get_Range("F4", "G4").Merge(false);
excel.Cells[1, 1] = name;
excel.Cells[3, 1] = dw + " " + date;
(excel.Cells[1, 1] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
(excel.Cells[3, 1] as Excel.Range).HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
excel.get_Range("A4", "m5").HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
excel.get_Range("A1", "S5").Font.Bold = true;
excel.Cells[4, "A"] = "序号";
excel.Cells[4, "B"] = "合同号";
excel.Cells[4, "C"] = "客户";
excel.Cells[4, "D"] = "产品名称";
excel.Cells[4, "E"] = "上月余额";
excel.Cells[4, "F"] = "本月";
excel.Cells[4, "H"] = "结转下月余额";
excel.Cells[5, "f"] = "估验金额";
excel.Cells[5, "g"] = "冲估验金额";
excel.Cells[4, "I"] = "备注";
excel.get_Range("D6", excel.Cells[dataGridView1.Rows.Count + 5, "H"]).NumberFormat = "#,##0.00";
//填充数据
for (int i = 0; i < dataGridView1.RowCount; i++)
{
//if (decimal.Parse(dataGridView1[5, i].Value.ToString() == "" ? "0" : dataGridView1[5, i].Value.ToString()) == 0 && decimal.Parse(dataGridView1[6, i].Value.ToString() == "" ? "0" : dataGridView1[6, i].Value.ToString()) == 0)
//{
// continue;
//}
for (int j = 0; j < dataGridView1.ColumnCount; j++)
{
if (dataGridView1[j, i].ValueType == typeof(string))
{
excel.Cells[i + 6, j + 1] = "'" + dataGridView1[j, i].Value.ToString();
}
else
{
excel.Cells[i + 6, j + 1] = dataGridView1[j, i].Value.ToString();
}
}
}
//for (int i = 7; i < this.dataGridView1.Rows.Count; i++)
//{
// if (excel.Cells[i, 2].ToString() == "System.__ComObject")
// {
// excel.get_Range("A" + i, "J" + i).Select();
// excel.get_Range("A" + i, "J" + i).Delete(Excel.XlDeleteShiftDirection.xlShiftUp);
// }
//}
excel.get_Range("A1", excel.Cells[dataGridView1.Rows.Count + 5, dataGridView1.Columns.Count]).EntireColumn.AutoFit();
ClassCustom.DrawExcelBorders(excel, "A4", excel.Cells[dataGridView1.Rows.Count + 5, dataGridView1.Columns.Count]);
Excel.Worksheet sheet1 = excel.Worksheets[1] as Excel.Worksheet;
sheet1.PageSetup.PrintTitleRows = "$1:$5";
//sheet1.PageSetup.PaperSize = Excel.XlPaperSize.xlPaperFanfoldUS;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
MessageView.MessageErrorShow(ex);
return;
}
}