Asp.Net用OWC操作Excel
string connstr = System.Configuration.ConfigurationManager.ConnectionStrings["DqpiHrConnectionString"].ToString();
SqlConnection conn = new SqlConnection(connstr);
SqlDataAdapter sda = new SqlDataAdapter(sql1.Text, conn);
DataSet ds = new DataSet();
conn.Open();
sda.Fill(ds);
conn.Close();
OWC10.SpreadsheetClass xlsheet;
xlsheet= new OWC10.SpreadsheetClass();
DataRow dr;
int i = 0;
for(int ii=0;ii<ds.Tables[0].Rows.Count;ii++)
{
dr = ds.Tables[0].Rows[ii];
//合并单元格
xlsheet.get_Range(xlsheet.Cells[i+1, 1], xlsheet.Cells[i+1, 8]).set_MergeCells(true);
xlsheet.get_Range(xlsheet.Cells[i + 5, 1], xlsheet.Cells[i + 5, 3]).set_MergeCells(true);
xlsheet.get_Range(xlsheet.Cells[i + 5, 4], xlsheet.Cells[i + 5, 6]).set_MergeCells(true);
xlsheet.get_Range(xlsheet.Cells[i + 5, 7], xlsheet.Cells[i + 5, 8]).set_MergeCells(true);
xlsheet.ActiveSheet.Cells[i + 1, 1] = dr["姓名"].ToString() + "自然情况";
//字体加粗
xlsheet.get_Range(xlsheet.Cells[i + 1, 1], xlsheet.Cells[i + 1, 14]).Font.set_Bold(true);
//单元格文本水平居中对齐
xlsheet.get_Range(xlsheet.Cells[i + 1, 1], xlsheet.Cells[i + 1, 14]).set_HorizontalAlignment(OWC10.XlHAlign.xlHAlignCenter);
//设置字体大小
xlsheet.get_Range(xlsheet.Cells[i + 1, 1], xlsheet.Cells[i + 1, 14]).Font.set_Size(14);
//设置列宽
xlsheet.get_Range(xlsheet.Cells[i + 1, 8], xlsheet.Cells[i + 1, 8]).set_ColumnWidth(20);
相关新闻>>
- 发表评论
-
- 最新评论 更多>>