C# 未知行数的DocX循环表
我最近安装了DocX for asp.net,在为未知数量的行创建循环时遇到了一个问题 我正在为来自SQL server的用户创建报告。其中的一部分与历史有关,在每个报表的数据库中,创建的每个报表都有不同数量的行。有没有办法创建一个循环或类似的方法来输出未知数量的行C# 未知行数的DocX循环表,c#,sql,asp.net,loops,novacode-docx,C#,Sql,Asp.net,Loops,Novacode Docx,我最近安装了DocX for asp.net,在为未知数量的行创建循环时遇到了一个问题 我正在为来自SQL server的用户创建报告。其中的一部分与历史有关,在每个报表的数据库中,创建的每个报表都有不同数量的行。有没有办法创建一个循环或类似的方法来输出未知数量的行 for (int i = 0; i <= 2; i++) { t.Rows[i].Cells[0].Paragraphs.First().Append(Data from SQL); } t.Alignment =
for (int i = 0; i <= 2; i++)
{
t.Rows[i].Cells[0].Paragraphs.First().Append(Data from SQL);
}
t.Alignment = Alignment.center;
t.Design = TableDesign.TableGrid;
t.Rows[0].Cells[0].Paragraphs.First().Append("Update Date");
t.Rows[0].Cells[1].Paragraphs.First().Append("Update By");
t.Rows[0].Cells[2].Paragraphs.First().Append("Code");
t.Rows[0].Cells[3].Paragraphs.First().Append("Status/Description");
t.Rows[0].Cells[4].Paragraphs.First().Append("System");
t.Rows[1].Cells[0].Paragraphs.First().Append("update_date");
t.Rows[1].Cells[1].Paragraphs.First().Append("update_by");
t.Rows[1].Cells[2].Paragraphs.First().Append("codes");
t.Rows[1].Cells[3].Paragraphs.First().Append("status");
t.Rows[1].Cells[4].Paragraphs.First().Append("system");
for(inti=0;i这里是一个代码示例。我使用一个类来放置我的所有数据库信息
List<Education> eduList = aDoc.getAppEdu(aDoc.AppID);
if (refList.Count < 0)
{
appQue.AppendLine("Applicant did not supply Educational Background information." + Environment.NewLine).Bold();
}
else
{
foreach (Education ed in eduList)
{
Novacode.Table tblEdu = doc.AddTable(6, 1);
tblEdu.AutoFit = AutoFit.Contents;
tblEdu.Rows[0].Cells[0].Paragraphs.First().Append("Education").Bold().FontSize(13);
tblEdu.Rows[1].Cells[0].Paragraphs.First().Append("* School Name: "); tblEdu.Rows[1].Cells[0].Paragraphs.First().Append(ed.SchoolName).Bold(); ;
tblEdu.Rows[2].Cells[0].Paragraphs.First().Append("* City: ");
tblEdu.Rows[2].Cells[0].Paragraphs.First().Append(ed.City).Bold();
tblEdu.Rows[2].Cells[0].Paragraphs.First().Append("* State: ");
tblEdu.Rows[2].Cells[0].Paragraphs.First().Append(ed.EduState).Bold();
tblEdu.Rows[2].Cells[0].Paragraphs.First().Append("* Zip: ");
tblEdu.Rows[2].Cells[0].Paragraphs.First().Append(ed.Zip).Bold();
tblEdu.Rows[3].Cells[0].Paragraphs.First().Append("* From: ");
tblEdu.Rows[3].Cells[0].Paragraphs.First().Append(ed.SStartScho).Bold();
tblEdu.Rows[3].Cells[0].Paragraphs.First().Append("* To: ");
tblEdu.Rows[3].Cells[0].Paragraphs.First().Append(ed.SEndScho).Bold();
tblEdu.Rows[4].Cells[0].Paragraphs.First().Append("* Did you graduate? ");
string grad = "No";
if (ed.Graduate == true)
{
grad = "Yes";
}
tblEdu.Rows[4].Cells[0].Paragraphs.First().Append(grad).Bold();
tblEdu.Rows[5].Cells[0].Paragraphs.First().Append("* Diploma/Degree: "); tblEdu.Rows[5].Cells[0].Paragraphs.First().Append(ed.Degree).Bold();
doc.InsertTable(tblEdu);
appQue = doc.InsertParagraph();
}
}
List-eduList=aDoc.getAppEdu(aDoc.AppID);
如果(refList.Count<0)
{
appQue.AppendLine(“申请人未提供教育背景信息。”+Environment.NewLine).Bold();
}
其他的
{
foreach(教育列表中的教育)
{
Novacode.Table tblEdu=doc.AddTable(6,1);
tblEdu.AutoFit=AutoFit.Contents;
tblEdu.Rows[0].单元格[0].段落.First().Append(“Education”).Bold().FontSize(13);
tblEdu.Rows[1]。单元格[0]。段落.First().Append(“*学校名称:”);tblEdu.Rows[1]。单元格[0]。段落.First().Append(ed.SchoolName).Bold();
tblEdu.Rows[2].单元格[0].段落.First().Append(“*City:”);
tblEdu.Rows[2].单元格[0].段落.First().Append(ed.City).Bold();
tblEdu.Rows[2].单元格[0].段落.First().Append(“*状态:”);
tblEdu.Rows[2].单元格[0].段落.First().Append(ed.EduState).Bold();
tblEdu.Rows[2].单元格[0].段落.First().Append(“*Zip:”);
tblEdu.Rows[2].单元格[0].段落.First().Append(ed.Zip).Bold();
tblEdu.Rows[3].单元格[0].段落.First().Append(“*From:”);
tblEdu.Rows[3].单元格[0].段落.First().Append(ed.SStartScho).Bold();
tblEdu.Rows[3]。单元格[0]。段落.First()。追加(“*To:”);
tblEdu.Rows[3].单元格[0].段落.First().Append(ed.SEndScho).Bold();
tblEdu.Rows[4].单元格[0].段落.First().Append(“*你毕业了吗?”);
字符串grad=“否”;
如果(ed.Graduate==真)
{
grad=“是”;
}
tblEdu.Rows[4].单元格[0].段落.First().Append(grad).Bold();
tblEdu.Rows[5]。单元格[0]。段落.First().Append(“*文凭/学位:”);tblEdu.Rows[5]。单元格[0]。段落.First().Append(ed.Degree).Bold();
文件插入表(tblEdu);
appQue=doc.insert段落();
}
}
关于上面的代码:您是否用下面的硬编码值覆盖for循环设置的值?为什么?循环的目的是替换数据库标题下的行。我从来都不擅长循环。谢谢。您的问题解决了吗?我更改了代码,数据不是从数据库中填充的,而是硬编码的text@bert_148怎样您是否正在访问数据库中的数据,以及将其存储在什么中?