我遇到了PDFtable和多個表的問題。它將前兩個表格細化,但不超過兩個。我需要它與儘可能多的表一起工作。有沒有人有過此要求?PdfPTable我們可以用一個基於值的IF語句一個接一個地添加多個表嗎?
string firstN="";
string firstage="";
string firstNV= someValue;
int firstAgeV=110;
string firstNHobbie = someHobby;
string secondN="";
string secondage="";
string secondNV= someValue2
int secondAgeV=130;
string secondNHobbie = someHobby2;
//If value is not nothing i.e. has a value
if(firstN != "")
PdfPTable mTablePerson1= new PdfPTable(5);
mTablePerson1.WidthPercentage = 110f;
mTablePerson1.AddCell("Name");
mTablePerson1.AddCell("Age");
mTablePerson1.AddCell(firstNV);
mTablePerson1.AddCell(firstAgeV);
//if selected hobbies
PdfPTable mTablePerson1Hobbies = new PdfPTable(5);
mTablePerson1Hobbies.WidthPercentage = 110f;
mTablePerson1Hobbies.AddCell("Hobby");
mTablePerson1Hobbies.AddCell("firstNHobbie");
document.Add(mTablePerson1);
document.Add(mTablePerson1Hobbies);
}else if(secondN != "")
PdfPTable mTablePerson2 = new PdfPTable(5);
mTablePerson2.WidthPercentage = 110f;
mTablePerson2.AddCell("Name");
mTablePerson2.AddCell("Age");
mTablePerson2.AddCell(secondNV);
mTablePerson2.AddCell(secondAgeV);
//if selected hobbies
PdfPTable mTablePerson2Hobbies = new PdfPTable(5);
mTablePerson1Hobbies.WidthPercentage = 110f;
mTablePerson1Hobbies.AddCell("Hobby");
mTablePerson1Hobbies.AddCell("secondNHobbie");
document.Add(mTablePerson2);
document.Add(mTablePerson2Hobbies);
}
出於某種原因,這種設計隱藏了第二個人的表即mTablePerson2和mTablePerson2Hobbies。如果滿足firstN和secondN條件,如何添加所有表格?
您的代碼錯過了開頭的括號。 – mkl
謝謝@mkl我一定錯過了。 – Shucoder