我正在开发一个需要来自word模板的报告的项目。我没有数据时需要删除表头和边框。我尝试了很多方法,但是他们中的任何一个都在工作。
我的模板如下:
输出如下:
我想删除第2点的表格设计。
我的代码如下所示
DataTable dtPersonalInfo = new dalCoro_Report().GetNonEffCertPersonalInfo(MemberID);
DataTable dtUnitAppt = new dalCoro_Report().GetNonEffCertExperienceUnitAppt(MemberID);
DataTable dtCourseInfo = new dalCoro_Report().GetNonEffCertExperienceCourse(MemberID);
DataTable dtMedalInfo = new dalCoro_Report().GetNonEffCertExperienceMedal(MemberID);
DataTable dtUnMissionInfo = new dalCoro_Report().GetNonEffCertUN_MSN(MemberID);
if (dtPersonalInfo.Rows.Count == 0)
return;
var fileName = "ExperienceCert_" + dtPersonalInfo.Rows[0]["PersonalNo"] + ".doc";
var input = Server.MapPath(@"~\Coro_Report\Template\Certificates\6. Experience Cert2.doc");
var output = Server.MapPath(@"~\Coro_Report\Report\" + fileName);
var doc = new Document(input);
dtPersonalInfo.TableName = "PersonalInfo";
doc.MailMerge.ExecuteWithRegions(dtPersonalInfo);
if (dtUnitAppt.Rows.Count > 0)
{
doc.MailMerge.TrimWhitespaces = false;
dtUnitAppt.TableName = "UnitAppt";
//doc.MailMerge.ExecuteWithRegions(dtUnitAppt);
}
if (dtCourseInfo.Rows.Count > 0)
{
doc.MailMerge.TrimWhitespaces = false;
dtCourseInfo.TableName = "Course";
doc.MailMerge.ExecuteWithRegions(dtCourseInfo);
}
else
{
doc.MailMerge.RemoveEmptyRegions = true;
}
if (dtMedalInfo.Rows.Count > 0)
{
doc.MailMerge.TrimWhitespaces = false;
dtMedalInfo.TableName = "Medal";
doc.MailMerge.ExecuteWithRegions(dtMedalInfo);
}
if (dtUnMissionInfo.Rows.Count > 0)
{
doc.MailMerge.TrimWhitespaces = false;
dtUnMissionInfo.TableName = "UnMission";
doc.MailMerge.ExecuteWithRegions(dtUnMissionInfo);
}
doc.MailMerge.CleanupOptions = MailMergeCleanupOptions.RemoveUnusedRegions | MailMergeCleanupOptions.RemoveUnusedFields | MailMergeCleanupOptions.RemoveContainingFields | MailMergeCleanupOptions.RemoveEmptyParagraphs;
doc.MailMerge.DeleteFields();
//Save the document
doc.Save(output);
ViewReport(fileName);
答案 0 :(得分:0)
不确定如何在Aspose中执行此操作,但也许您可以尝试创建文档的两个部分(一个使用非空表,一个使用空表/不使用表)。
然后你可以像在Templater中解决它一样解决它,你可以看到例子:https://github.com/ngs-doo/TemplaterExamples/tree/master/Intermediate/WordDataTable%20(.NET)