C#下面调用 Excel 另存代码
来源:互联网 发布:人工智能语言的应用 编辑:程序博客网 时间:2024/05/01 16:41
<script type="text/javascript">google_ad_client = "pub-2048279401139630";google_ad_slot = "8856771542";google_ad_width = 728;google_ad_height = 90;document.write("<s"+"cript type='text/javascript' s"+"rc='http://pagead2.googlesyndication.com/pagead/show_ads"+"."+"js'></scr"+"ipt>");</script>
private void btnSaveAsData_Click(object sender, EventArgs e)
...{
Excel.Application xlsApp = new Excel.Application();
Excel._Workbook xlsBook = xlsApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
Excel._Worksheet xlsSheet = (Excel._Worksheet)xlsBook.Worksheets[1];
xlsSheet.Activate();
xlsApp.Caption = lblDMMC.Text + "断面实测成果表 - 另存为 ";
DataTable myDT1, myDT2;
myDT1 = datatable(a,a1);
myDT2 = datatable(a,a1);
double minGaocheng = 0;//Get_min(a1);
string[] strColName = new string[] ...{ "起点距m", "河底高程m", "起点距m", "河底高程m", "起点距m", "河底高程m", "起点距m", "河底高程m", "起点距m", "河底高程m", "起点距m", "河底高程m", "" };
int intCols = strColName.Length - 1;
int intRows = myDT1.Rows.Count;
int[] intRows1 = new int[myDT1.Rows.Count];
int[] intcols1 = new int[myDT1.Columns.Count];
int minrow = 0;
int mincol = 0;
int zhanyonghang = 3;
xlsSheet.Cells[2, 7] = lblDMMC.Text + "断面实测成果表";
xlsSheet.Cells[zhanyonghang+2, intCols + 1] = "制";
xlsSheet.Cells[zhanyonghang + 3, intCols + 1] = "表";
xlsSheet.Cells[zhanyonghang + 4, intCols + 1] = ":";
xlsSheet.Cells[zhanyonghang + 7, intCols + 1] = "一";
xlsSheet.Cells[zhanyonghang + 8, intCols + 1] = "校";
xlsSheet.Cells[zhanyonghang + 9, intCols + 1] = ":";
xlsSheet.Cells[zhanyonghang + 12, intCols + 1] = "二";
xlsSheet.Cells[zhanyonghang + 13, intCols + 1] = "校";
xlsSheet.Cells[zhanyonghang + 14, intCols + 1] = ":";
xlsSheet.Cells[zhanyonghang + 17, intCols + 1] = "验";
xlsSheet.Cells[zhanyonghang + 18, intCols + 1] = "收";
xlsSheet.Cells[zhanyonghang + 19, intCols + 1] = ":";
xlsSheet.Cells[zhanyonghang + 1, 3] = "施测日期:" + dtpS3.Text;
xlsSheet.Cells[zhanyonghang + 1, 7] = "测探工具:测探杆 ";
xlsSheet.Cells[zhanyonghang + 1, 10] = "水位:" + txtS4.Text + "m";
// xlsSheet.Cells[1, intCols] = "制表:";
for (int j = 0; j < intCols; j++)
...{
xlsSheet.Cells[zhanyonghang + 2, j + 1] = strColName[j];
}
int tempi = 1;
for (int i = 0; i < intRows; i++)
...{
for (int j = 0; j < intCols; j++)
...{
if (i == temprows2 && j == tempcols2)
...{
myDT1.Rows[i][j] = myDT1.Rows[i][j].ToString() + "▲";
}
if (i == temprows1 && j == tempcols1)
...{
myDT1.Rows[i][j] = myDT1.Rows[i][j].ToString() + "▼";
}
xlsApp.Cells[zhanyonghang + i + 3, j + 1] = myDT1.Rows[i][j];
}
}
xlsSheet.Cells[zhanyonghang + intRows + 3,6] = "附注:" + txtFuzhu.Text;
xlsSheet.Columns.ColumnWidth = 9;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, intCols + 1], xlsSheet.Cells[zhanyonghang + intRows + 2, intCols + 1]).ColumnWidth = 3;
xlsSheet.Rows.RowHeight = 18;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, 1], xlsSheet.Cells[zhanyonghang + 2, intCols]).RowHeight = 15;
xlsSheet.Cells.Font.Name = "宋体";
xlsSheet.Cells.Font.Size = 10;
xlsSheet.Cells.Font.Bold = false;
xlsSheet.Cells.WrapText = false;
xlsSheet.get_Range(xlsSheet.Cells[ 2, 1], xlsSheet.Cells[ 2, intCols]).Font.Size = 15;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, 1], xlsSheet.Cells[zhanyonghang + 2, intCols]).Font.Name = "宋体";
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, 1], xlsSheet.Cells[zhanyonghang + 2, intCols]).Font.Size = 10;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, 1], xlsSheet.Cells[zhanyonghang + 2, intCols]).Font.Bold = true;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, 1], xlsSheet.Cells[zhanyonghang + 2, intCols]).WrapText = false;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + temprows3 + 3, tempcols3], xlsSheet.Cells[zhanyonghang + temprows3 + 3, tempcols3 + 1]).Font.Underline = true;
for (int i = 0; i < myDT2.Rows.Count; i++)
...{
for (int j = 0; j < myDT2.Columns.Count; j++)
...{
double temp1;
if (myDT2.Rows[i][j].ToString() == "")
...{
temp1 = 0.123456;
}
else
...{
temp1 = Convert.ToDouble(myDT2.Rows[i][j].ToString());
}
if (j % 2 == 0)
...{
if (temp1 == 0)
...{
xlsSheet.Cells[zhanyonghang + i + 3, j + 1] = 0;
}
else if (temp1 == 0.123456)
...{
xlsSheet.Cells[i + 3, j + 1] = "";
}
else
...{
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + i + 3, j + 1], xlsSheet.Cells[zhanyonghang + i + 3, j + 1]).NumberFormatLocal = "#####";
}
}
else
...{
if (temp1 > 9)
...{
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + i + 3, j + 1], xlsSheet.Cells[zhanyonghang + i + 3, j + 1]).NumberFormatLocal = "#####.0";
}
}
}
}
// xlsSheet.get_Range(xlsSheet.Cells[3, 6], xlsSheet.Cells[3, 6]).NumberFormatLocal = "#####.0";
//xlsSheet.get_Range(xlsSheet.Cells[3, 4], xlsSheet.Cells[intRows + 2, 4]).NumberFormatLocal = "#####.0";
//xlsSheet.get_Range(xlsSheet.Cells[3, 6], xlsSheet.Cells[intRows + 2, 6]).NumberFormatLocal = "#####.0";
//xlsSheet.get_Range(xlsSheet.Cells[3, 8], xlsSheet.Cells[intRows + 2, 8]).NumberFormatLocal = "#####.0";
//xlsSheet.get_Range(xlsSheet.Cells[3, 10], xlsSheet.Cells[intRows + 2, 10]).NumberFormatLocal = "#####.0";
//xlsSheet.get_Range(xlsSheet.Cells[3, 12], xlsSheet.Cells[intRows + 2, 12]).NumberFormatLocal = "#####.0";
xlsSheet.Columns.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
xlsSheet.Columns.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 1, intCols], xlsSheet.Cells[zhanyonghang + 1, intCols]).HorizontalAlignment = Excel.XlHAlign.xlHAlignRight;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, 1], xlsSheet.Cells[zhanyonghang + intRows + 2, intCols]).Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, 1], xlsSheet.Cells[zhanyonghang + intRows + 2, intCols]).Borders.Weight = Excel.XlBorderWeight.xlThin;
string FileName = xlsApp.GetSaveAsFilename("断面实测成果表 .xls", "Excel文件 (*.xls), *.xls", 1, "断面实测成果表", "断面实测成果表").ToString().Trim();
if (FileName != "False" && FileName != "")
...{
xlsSheet.SaveAs(FileName, Excel.XlFileFormat.xlExcel9795, "", "", false, false, false, 1, 1, true);
}
xlsBook.Saved = true;
xlsApp.Workbooks.Close();
xlsApp.Quit();
}
...{
Excel.Application xlsApp = new Excel.Application();
Excel._Workbook xlsBook = xlsApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
Excel._Worksheet xlsSheet = (Excel._Worksheet)xlsBook.Worksheets[1];
xlsSheet.Activate();
xlsApp.Caption = lblDMMC.Text + "断面实测成果表 - 另存为 ";
DataTable myDT1, myDT2;
myDT1 = datatable(a,a1);
myDT2 = datatable(a,a1);
double minGaocheng = 0;//Get_min(a1);
string[] strColName = new string[] ...{ "起点距m", "河底高程m", "起点距m", "河底高程m", "起点距m", "河底高程m", "起点距m", "河底高程m", "起点距m", "河底高程m", "起点距m", "河底高程m", "" };
int intCols = strColName.Length - 1;
int intRows = myDT1.Rows.Count;
int[] intRows1 = new int[myDT1.Rows.Count];
int[] intcols1 = new int[myDT1.Columns.Count];
int minrow = 0;
int mincol = 0;
int zhanyonghang = 3;
xlsSheet.Cells[2, 7] = lblDMMC.Text + "断面实测成果表";
xlsSheet.Cells[zhanyonghang+2, intCols + 1] = "制";
xlsSheet.Cells[zhanyonghang + 3, intCols + 1] = "表";
xlsSheet.Cells[zhanyonghang + 4, intCols + 1] = ":";
xlsSheet.Cells[zhanyonghang + 7, intCols + 1] = "一";
xlsSheet.Cells[zhanyonghang + 8, intCols + 1] = "校";
xlsSheet.Cells[zhanyonghang + 9, intCols + 1] = ":";
xlsSheet.Cells[zhanyonghang + 12, intCols + 1] = "二";
xlsSheet.Cells[zhanyonghang + 13, intCols + 1] = "校";
xlsSheet.Cells[zhanyonghang + 14, intCols + 1] = ":";
xlsSheet.Cells[zhanyonghang + 17, intCols + 1] = "验";
xlsSheet.Cells[zhanyonghang + 18, intCols + 1] = "收";
xlsSheet.Cells[zhanyonghang + 19, intCols + 1] = ":";
xlsSheet.Cells[zhanyonghang + 1, 3] = "施测日期:" + dtpS3.Text;
xlsSheet.Cells[zhanyonghang + 1, 7] = "测探工具:测探杆 ";
xlsSheet.Cells[zhanyonghang + 1, 10] = "水位:" + txtS4.Text + "m";
// xlsSheet.Cells[1, intCols] = "制表:";
for (int j = 0; j < intCols; j++)
...{
xlsSheet.Cells[zhanyonghang + 2, j + 1] = strColName[j];
}
int tempi = 1;
for (int i = 0; i < intRows; i++)
...{
for (int j = 0; j < intCols; j++)
...{
if (i == temprows2 && j == tempcols2)
...{
myDT1.Rows[i][j] = myDT1.Rows[i][j].ToString() + "▲";
}
if (i == temprows1 && j == tempcols1)
...{
myDT1.Rows[i][j] = myDT1.Rows[i][j].ToString() + "▼";
}
xlsApp.Cells[zhanyonghang + i + 3, j + 1] = myDT1.Rows[i][j];
}
}
xlsSheet.Cells[zhanyonghang + intRows + 3,6] = "附注:" + txtFuzhu.Text;
xlsSheet.Columns.ColumnWidth = 9;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, intCols + 1], xlsSheet.Cells[zhanyonghang + intRows + 2, intCols + 1]).ColumnWidth = 3;
xlsSheet.Rows.RowHeight = 18;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, 1], xlsSheet.Cells[zhanyonghang + 2, intCols]).RowHeight = 15;
xlsSheet.Cells.Font.Name = "宋体";
xlsSheet.Cells.Font.Size = 10;
xlsSheet.Cells.Font.Bold = false;
xlsSheet.Cells.WrapText = false;
xlsSheet.get_Range(xlsSheet.Cells[ 2, 1], xlsSheet.Cells[ 2, intCols]).Font.Size = 15;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, 1], xlsSheet.Cells[zhanyonghang + 2, intCols]).Font.Name = "宋体";
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, 1], xlsSheet.Cells[zhanyonghang + 2, intCols]).Font.Size = 10;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, 1], xlsSheet.Cells[zhanyonghang + 2, intCols]).Font.Bold = true;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, 1], xlsSheet.Cells[zhanyonghang + 2, intCols]).WrapText = false;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + temprows3 + 3, tempcols3], xlsSheet.Cells[zhanyonghang + temprows3 + 3, tempcols3 + 1]).Font.Underline = true;
for (int i = 0; i < myDT2.Rows.Count; i++)
...{
for (int j = 0; j < myDT2.Columns.Count; j++)
...{
double temp1;
if (myDT2.Rows[i][j].ToString() == "")
...{
temp1 = 0.123456;
}
else
...{
temp1 = Convert.ToDouble(myDT2.Rows[i][j].ToString());
}
if (j % 2 == 0)
...{
if (temp1 == 0)
...{
xlsSheet.Cells[zhanyonghang + i + 3, j + 1] = 0;
}
else if (temp1 == 0.123456)
...{
xlsSheet.Cells[i + 3, j + 1] = "";
}
else
...{
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + i + 3, j + 1], xlsSheet.Cells[zhanyonghang + i + 3, j + 1]).NumberFormatLocal = "#####";
}
}
else
...{
if (temp1 > 9)
...{
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + i + 3, j + 1], xlsSheet.Cells[zhanyonghang + i + 3, j + 1]).NumberFormatLocal = "#####.0";
}
}
}
}
// xlsSheet.get_Range(xlsSheet.Cells[3, 6], xlsSheet.Cells[3, 6]).NumberFormatLocal = "#####.0";
//xlsSheet.get_Range(xlsSheet.Cells[3, 4], xlsSheet.Cells[intRows + 2, 4]).NumberFormatLocal = "#####.0";
//xlsSheet.get_Range(xlsSheet.Cells[3, 6], xlsSheet.Cells[intRows + 2, 6]).NumberFormatLocal = "#####.0";
//xlsSheet.get_Range(xlsSheet.Cells[3, 8], xlsSheet.Cells[intRows + 2, 8]).NumberFormatLocal = "#####.0";
//xlsSheet.get_Range(xlsSheet.Cells[3, 10], xlsSheet.Cells[intRows + 2, 10]).NumberFormatLocal = "#####.0";
//xlsSheet.get_Range(xlsSheet.Cells[3, 12], xlsSheet.Cells[intRows + 2, 12]).NumberFormatLocal = "#####.0";
xlsSheet.Columns.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
xlsSheet.Columns.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 1, intCols], xlsSheet.Cells[zhanyonghang + 1, intCols]).HorizontalAlignment = Excel.XlHAlign.xlHAlignRight;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, 1], xlsSheet.Cells[zhanyonghang + intRows + 2, intCols]).Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
xlsSheet.get_Range(xlsSheet.Cells[zhanyonghang + 2, 1], xlsSheet.Cells[zhanyonghang + intRows + 2, intCols]).Borders.Weight = Excel.XlBorderWeight.xlThin;
string FileName = xlsApp.GetSaveAsFilename("断面实测成果表 .xls", "Excel文件 (*.xls), *.xls", 1, "断面实测成果表", "断面实测成果表").ToString().Trim();
if (FileName != "False" && FileName != "")
...{
xlsSheet.SaveAs(FileName, Excel.XlFileFormat.xlExcel9795, "", "", false, false, false, 1, 1, true);
}
xlsBook.Saved = true;
xlsApp.Workbooks.Close();
xlsApp.Quit();
}
- C#下面调用 Excel 另存代码
- c#中调用Excel
- C# 调用Excel
- C# 导出Excel代码
- C# 写Excel 代码
- C# 写Excel 代码
- 【代码】C#导出Excel
- 静态代码在内存中的调用过程
- excel的另类玩法-另存“xml数据”后利用c#开发各种应用
- 编程实现C#调用Excel
- C#对Excel的调用
- 在C#中调用Excel
- C#调用Excel VBA宏
- C#调用epplus 创建Excel
- C#调用epplus 创建Excel
- C#调用Excel VBA宏
- C#调用Excel的宏
- C#调用Excel模版生成Excel文件
- 考试方法--给朋友的一封信
- 用like语句时的C#格式化函数
- 五一BLOG访问过1000标记一下
- T-SQL经验总结
- 多层架构解析
- C#下面调用 Excel 另存代码
- 开发过程
- 注册表笔记
- 什么是迭代和增加的开发
- [转载]Redhat Linux AS 4安装Oracle 9.2.0.4
- 可视化建模1[图]
- Java与常用数据的连接
- Java连接各种数据库的实例
- servlet的实现