导出数据到Excel模版并合并单元格

更新时间:2023-05-13 07:19:19 阅读: 评论:0

导出数据到Excel模版并合并单元格
营业厅英文
protected void btnExport_ServerClick(object nder, EventArgs e)
{
2016研究生国家线string strFileName = Server.MapPath(@"SalaryModel.xlsx");
string strSaveFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + @".xls";
Excel.Application ThisApplication = new Excel.Application();
Excel.Workbook ThisWorkBook;
object missing = System.Reflection.Missing.Value;
try
英文翻译成中文{
//加载Excel模板⽂件
ThisWorkBook = ThisApplication.Workbooks.Open(strFileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Excel.Worksheet ThisSheet = (Excel.Worksheet)ThisWorkBook.Sheets[1];
aniusThisApplication.Visible = fal;
int nums;
int j=0;
int beforeRecords = 0;
if (ds != null)
{
if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < RCount; i++)
{
#region 合并单元格
yongle
if (j < ds.Tables[1].Rows.Count)
{
if (i == beforeRecords)
{
nums = Convert.ToInt32(ds.Tables[1].Rows[j]["projnums"].ToString());
beforeRecords += nums;
j++;
Excel.Range range;
range = _Range(ThisSheet.Cells[i + 6, 1], ThisSheet.Cells[i + 6 + nums - 1, 1]);
range.MergeCells = true;
range.t_Value(Type.Missing, j.ToString());
range = _Range(ThisSheet.Cells[i + 6, 2], ThisSheet.Cells[i + 6 + nums - 1, 2]);
range.MergeCells = true;
range.t_Value(Type.Missing, ds.Tables[0].Rows[i]["UrName"].ToString());
range = _Range(ThisSheet.Cells[i + 6, 3], ThisSheet.Cells[i + 6 + nums - 1, 3]);初中一对一辅导补习班
range.MergeCells = true;
range.t_Value(Type.Missing, ds.Tables[0].Rows[i]["MonthlyTask"].ToString());
range = _Range(ThisSheet.Cells[i + 6, 4], ThisSheet.Cells[i + 6 + nums - 1, 4]);
range.MergeCells = true;
快速阅读记忆
range.t_Value(Type.Missing, ds.Tables[0].Rows[i]["AppOverTimeMoney"].ToString());
range = _Range(ThisSheet.Cells[i + 6, 26], ThisSheet.Cells[i + 6 + nums - 1, 26]);                                    range.MergeCells = true;
lara loganrange.t_Value(Type.Missing, ds.Tables[0].Rows[i]["Sumtotal"].ToString());
}
}
#endregion
//ThisSheet.Cells[i + 6, 1] = j.ToString();
//ThisSheet.Cells[i + 6, 2] = ds.Tables[0].Rows[i]["UrName"].ToString();
//ThisSheet.Cells[i + 6, 3] = ds.Tables[0].Rows[i]["MonthlyTask"].ToString();
//ThisSheet.Cells[i + 6, 4] = ds.Tables[0].Rows[i]["AppOverTimeMoney"].ToString();
ThisSheet.Cells[i + 6, 5] = ds.Tables[0].Rows[i]["ProjectName"].ToString();
ThisSheet.Cells[i + 6, 6] = ds.Tables[0].Rows[i]["SetCostNum"].ToString();
ThisSheet.Cells[i + 6, 7] = ds.Tables[0].Rows[i]["SetOverNum"].ToString();
ThisSheet.Cells[i + 6, 8] = ds.Tables[0].Rows[i]["ContractMoney"].ToString();
ThisSheet.Cells[i + 6, 9] = ds.Tables[0].Rows[i]["OwnCourt"].ToString();
ThisSheet.Cells[i + 6, 10] = ds.Tables[0].Rows[i]["Outskirt"].ToString();
ThisSheet.Cells[i + 6, 11] = ds.Tables[0].Rows[i]["ServiceContract"].ToString();
ThisSheet.Cells[i + 6, 12] = ds.Tables[0].Rows[i]["sbys"].ToString();
ThisSheet.Cells[i + 6, 13] = ds.Tables[0].Rows[i]["gjfys"].ToString();
ThisSheet.Cells[i + 6, 14] = ds.Tables[0].Rows[i]["wwfys"].ToString();
ThisSheet.Cells[i + 6, 15] = ds.Tables[0].Rows[i]["rgfys"].ToString();
ThisSheet.Cells[i + 6, 16] = ds.Tables[0].Rows[i]["InnerBidBudget"].ToString();
ThisSheet.Cells[i + 6, 17] = ds.Tables[0].Rows[i]["sbjs"].ToString();
ThisSheet.Cells[i + 6, 18] = ds.Tables[0].Rows[i]["gjfjs"].ToString();
ThisSheet.Cells[i + 6, 19] = ds.Tables[0].Rows[i]["wwfjs"].ToString();
ThisSheet.Cells[i + 6, 20] = ds.Tables[0].Rows[i]["rgfjs"].ToString();
ThisSheet.Cells[i + 6, 21] = ds.Tables[0].Rows[i]["ProjectFee"].ToString();
ThisSheet.Cells[i + 6, 22] = ds.Tables[0].Rows[i]["ProjectReview"].ToString();
ThisSheet.Cells[i + 6, 23] = ds.Tables[0].Rows[i]["ExecutionContract"].ToString();
ThisSheet.Cells[i + 6, 24] = ds.Tables[0].Rows[i]["Visa"].ToString();
ThisSheet.Cells[i + 6, 25] = ds.Tables[0].Rows[i]["Subtotal"].ToString();
//ThisSheet.Cells[i + 6, 26] = ds.Tables[0].Rows[i]["Sumtotal"].ToString();
}
}
保鲜膜英文
}
//更新数据后另存为新⽂件
ThisSheet.SaveAs(strSaveFileName, missing, missing, missing, missing, missing, missing, missing, missing, missing);
}
catch(Exception ex) {
Respon.Write(ex.Message.ToString());
}
finally
{
ThisApplication.Quit();
ThisWorkBook = null;
ThisApplication = null;
}
try
{ //打开刚才⽣成的Excel⽂件
Microsoft.Office.Interop.Excel.Workbook NewWorkBook;
Microsoft.Office.Interop.Excel.Application NewApplication = new Microsoft.Office.Interop.Excel.ApplicationClass();                NewWorkBook = NewApplication.Workbooks.Open(strSaveFileName, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Microsoft.Office.Interop.Excel.Worksheet NewSheet =
(Microsoft.Office.Interop.Excel.Worksheet)NewWorkBook.Sheets[1];
刘艺彬
NewApplication.Visible = true;
/
/也可以使⽤System.Diagnostics.Process.Start(strSaveFileName);来打开新⽂件
}
catch (Exception ex)
{
Respon.Write(ex.Message.ToString());
}
}

本文发布于:2023-05-13 07:19:19,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/106663.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:模版   研究生   模板   辅导   阅读
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图