• 批量导出Word


    /// <summary>
    /// 批量导出
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void exportWord_Click(object sender, EventArgs e)
    {
      hfSelectedIDS.Text = Common.SyncSelectedRowIndexArrayToHiddenField(hfSelectedIDS.Text, Grid1);
      List<int> ids = Common.GetSelectedRowIndexArrayFromHiddenField(hfSelectedIDS.Text);
      if (ids.Count == 0)
      {
        Alert.Show("至少选择一个委托单!");
        return;
      }
    FileName.Text = DateTime.Now.ToString("yyyyMMddhhmmss") + ".docx";
    string SavaFilesPath = Server.MapPath(("~\UploadFiles\") + FileName.Text);
    string DotFileName = Server.MapPath("~\dot\") + "JS-41120.docx";
    Novacode.DocX wordDocTmp = null;
    Novacode.DocX wordDoc = null;
    int i = 0;

    string SavaFilesPath2 = Server.MapPath(("~\UploadFiles\") + FileName.Text);
    string DotFileName2 = Server.MapPath("~\dot\") + "20200710015323.docx";
    Novacode.DocX wordDoc2 = null;

    foreach (int AID in ids)
    {
    wordDoc = WordReportDocX.LoadTemplateDocument(DotFileName);
    wordDoc2 = WordReportDocX.LoadTemplateDocument(DotFileName2);

    try
    {
    DataTable dt = Govaze.SQLServerDAL.Factory.getDataXmlDAL().ProcDataTable("<root><Type>ApplicationInfo</Type><AID>" + AID.ToString() + "</AID></root>", "DataXmlApplication");


    DataTable dtTestItem = Govaze.SQLServerDAL.Factory.getDataXmlDAL().ProcDataTable("<root><Type>SYXM</Type><KeyWord>金属检测</KeyWord></root>", "DataXmlProject");


    //涡流、金相检测项目放到其他内;从结果中移除涡流、金相
    DataRow[] drS = dtTestItem.Select("ObjectName = '涡流' or ObjectName = '金相'");

    foreach (DataRow dr in drS)
    {
    dtTestItem.Rows.Remove(dr);

    }
    var rows = dtTestItem.Rows.Cast<DataRow>();


    string[] ObjectNames = rows.Select(d => d.Field<string>("ObjectName")).Skip(0).Take(4).ToArray();

    StringBuilder p = new StringBuilder();
    p.Append("□" + String.Join(" □", ObjectNames));

    for (int n = 1; n <= (dtTestItem.Rows.Count / 4); n++)
    {
    ObjectNames = rows.Select(d => d.Field<string>("ObjectName")).Skip(n * 4).Take(4).ToArray();
    p.AppendLine("□" + String.Join(" □", ObjectNames));

    }

    WordReportDocX.InsertText(wordDoc, "$KeyWord$", dt.Rows[0]["KeyWord"].ToString());
    WordReportDocX.InsertText(wordDoc, "$SnID$", dt.Rows[0]["SnID"].ToString());
    WordReportDocX.InsertText(wordDoc, "$KeyWord$", dt.Rows[0]["KeyWord"].ToString());
    WordReportDocX.InsertText(wordDoc, "$SnID$", dt.Rows[0]["SnID"].ToString());

    string EntryType = dt.Rows[0]["EntryType"].ToString();
    if (EntryType == "涡流" || EntryType == "金相")
    {
    EntryType = "其他";
    }

    WordReportDocX.InsertText(wordDoc, "$EntryType$", p.ToString().Replace("□" + EntryType, "☑" + EntryType));

    WordReportDocX.InsertText(wordDoc, "$Text1$", dt.Rows[0]["Text1"].ToString());
    WordReportDocX.InsertText(wordDoc, "$Text2$", dt.Rows[0]["Text2"].ToString());
    WordReportDocX.InsertText(wordDoc, "$Text3$", dt.Rows[0]["Text3"].ToString());
    WordReportDocX.InsertText(wordDoc, "$Text4$", dt.Rows[0]["Text4"].ToString());
    WordReportDocX.InsertText(wordDoc, "$Text5$", dt.Rows[0]["Text5"].ToString());

    WordReportDocX.InsertText(wordDoc, "$Cperson2$", dt.Rows[0]["Cperson2"].ToString());
    WordReportDocX.InsertText(wordDoc, "$CreateTime2$", dt.Rows[0]["CreateTime2"].ToString());

    }
    catch
    {
    Alert.Show("加载流程数据失败!");
    }

    List<d_YWZC_dis_Sample_TestItem_CE_Model> list2 = Govaze.SQLServerDAL.Factory.geta17025DAL().d_YWZC_dis_Report_SYD_bySampleAID_TestItem(AID, getUserName());
    if (list2.Count > 10)
    {
    WordReportDocX.AddRow(wordDoc2, 1, list2.Count - 10);
    }

    int rowNumber = 6;
    foreach (d_YWZC_dis_Sample_TestItem_CE_Model s in list2)
    {
    if (rowNumber <= 15)
    {
    WordReportDocX.InsertCell(wordDoc, 1, rowNumber, 1, s.Text001);
    WordReportDocX.InsertCell(wordDoc, 1, rowNumber, 2, s.Text002);
    WordReportDocX.InsertCell(wordDoc, 1, rowNumber, 3, s.ItemName);
    WordReportDocX.InsertCell(wordDoc, 1, rowNumber, 4, s.Text003);
    WordReportDocX.InsertCell(wordDoc, 1, rowNumber, 5, s.ItemName1);
    WordReportDocX.InsertCell(wordDoc, 2, rowNumber, 1, s.Text001);
    WordReportDocX.InsertCell(wordDoc, 2, rowNumber, 2, s.Text002);
    WordReportDocX.InsertCell(wordDoc, 2, rowNumber, 3, s.ItemName);
    WordReportDocX.InsertCell(wordDoc, 2, rowNumber, 4, s.Text003);
    WordReportDocX.InsertCell(wordDoc, 2, rowNumber, 5, s.ItemName1);
    WordReportDocX.InsertCell(wordDoc, 3, rowNumber, 1, s.Text001);
    WordReportDocX.InsertCell(wordDoc, 3, rowNumber, 2, s.Text002);
    WordReportDocX.InsertCell(wordDoc, 3, rowNumber, 3, s.ItemName);
    WordReportDocX.InsertCell(wordDoc, 3, rowNumber, 4, s.Text003);
    WordReportDocX.InsertCell(wordDoc, 3, rowNumber, 5, s.ItemName1);
    }
    else
    {
    WordReportDocX.InsertCell(wordDoc2, 1, rowNumber - 14, 1, s.Text001);
    WordReportDocX.InsertCell(wordDoc2, 1, rowNumber - 14, 2, s.Text002);
    WordReportDocX.InsertCell(wordDoc2, 1, rowNumber - 14, 3, s.ItemName);
    WordReportDocX.InsertCell(wordDoc2, 1, rowNumber - 14, 4, s.Text003);
    WordReportDocX.InsertCell(wordDoc2, 1, rowNumber - 14, 5, s.ItemName1);
    }

    rowNumber++;
    }

    if (list2.Count > 10)
    {
    wordDoc.Paragraphs[wordDoc.Paragraphs.Count - 1].InsertPageBreakAfterSelf();
    wordDoc.InsertDocument(wordDoc2);
    WordReportDocX.AddRow(wordDoc2, 1, list2.Count - 10);
    }


    if (i == 0)
    {
    wordDoc.SaveAs(SavaFilesPath);
    wordDocTmp = WordReportDocX.LoadTemplateDocument(SavaFilesPath);
    }
    else
    {
    wordDocTmp.Paragraphs[wordDocTmp.Paragraphs.Count - 1].InsertPageBreakAfterSelf();
    wordDocTmp.InsertDocument(wordDoc);
    }
    i++;


    List<d_YWZC_dis_Main_Attach_Model> list = Govaze.SQLServerDAL.Factory.getCB719DAL().d_YWZC_dis_Main_Attach(AID, getUserName());

    if (list.Count > 0)
    {
    for (int j = 0; j < list.Count; j++)
    {
    if (list[j].DocPath.Contains("doc") || list[j].DocPath.Contains("docx"))
    {

    wordDoc2 = WordReportDocX.LoadTemplateDocument(Server.MapPath(("~\UploadFiles\SYLCAttachFile\") + list[j].DocPath));
    wordDocTmp.Paragraphs[wordDocTmp.Paragraphs.Count - 1].InsertPageBreakAfterSelf();
    wordDocTmp.InsertDocument(wordDoc2);

    }

    }
    }


    }

    wordDocTmp.SaveAs(SavaFilesPath);
    Document Doc = new Document(SavaFilesPath);
    Doc.Save(SavaFilesPath, SaveFormat.Docx);
    FileName.Text = SavaFilesPath;

    WindowWord.Hidden = false;
    PageContext.RegisterStartupScript(WindowWord.GetHidePostBackReference());
    return;


    }

  • 相关阅读:
    [易语言] 六边形扫雷游戏实战开发
    [web开发] 利用微信小程序开发上海大学失物招领平台
    [web开发] Vue + spring boot + echart 微博爬虫展示平台
    [web开发] Vue+Spring Boot 上海大学预约系统开发记录
    [神经网络]一步一步使用Mobile-Net完成视觉识别(一)
    Python中操作ini配置文件
    python操作mySQL数据库
    使用python和selenium写一个百度搜索的case
    功能测试的过程中有关数据安全性的检查点
    python主流测试框架的简介
  • 原文地址:https://www.cnblogs.com/sanshengshitouhua/p/14355072.html
Copyright © 2020-2023  润新知