我正在编写一个程序,它从 SQLite 文件中检索 Cutomer 数据并将它们存储在 PDF 文件中的 PdfTable 中,例如:
PdfContents contentsTable = new PdfContents(page);
PdfTable table = new PdfTable(page, contentsTable, ArialNormal, fontSize);
table.TableArea = new PdfRectangle(border (2 * border + fontHight), (210 - border), (297 - (2 * border + 4 * linespacing + 5 * fontHight))); // <- 'border', 'fontHight' and 'linespacing' are simply variables i use to define lengths that also apear at other locations
table.SetColumnWidth(30, 75, 35, 10, 30, 22, 8);
table.HeaderOnEachPage = true;
table.MinRowHight = 5;
table.Header[0].Style = table.HeaderStyle;
table.Header[1].Style = table.HeaderStyle;
table.Header[2].Style = table.HeaderStyle;
table.Header[3].Style = table.HeaderStyle;
table.Header[4].Style = table.HeaderStyle;
table.Header[5].Style = table.HeaderStyle;
table.Header[6].Style = table.HeaderStyle;
table.Header[0].Value = "CODE";
table.Header[1].Value = "BESCHREIBUNG";
table.Header[2].Value = "MATERIALNAME";
table.Header[3].Value = "NoFl";
table.Header[4].Value = "ERGEBNIST";
table.Header[5].Value = "BEWERTUNG";
table.Header[6].Value = "ART";
// Querys the 'ANALYT' and 'RESULTS' Table and Adds the Answers into the Table in the PDF-File
using (var connection = new SQLiteConnection("Data Source = " + dbFile)) // <- 'dbFile' contains the Path to the File
{
// Opens the connection to the SQLite File
connection.Open();
var command = connection.CreateCommand();
command.CommandText = "select A.CODE, A.BESCHERIBUNG, A.MATERIALNAME, R.NORMFLAG, R.ERGEBNIST, R.BEWERTUNG, R.ART " +
"from ANALYT A, RESULTS R " +
"and A.ANALYTX = R.ANALYTX " +
"order by A.MATERIALNAME desc, R.SORT ";
using (var reader = command.ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
table.Cell[0].Value = reader[0].ToString();
table.Cell[1].Value = reader[1].ToString();
table.Cell[2].Value = reader[2].ToString();
table.Cell[3].Value = reader[3].ToString();
table.Cell[4].Value = reader[4].ToString();
table.Cell[5].Value = reader[5].ToString();
table.Cell[6].Value = reader[6].ToString();
}
contentToBeAdded = true; // <- A variable i use to determine if the processes are all successfull
}
else
{
// Code that lets the user know something went wrong
}
connection.Close();
}
table.Close();
document.CreateFile();
这段代码几乎在所有情况下都能正常工作,但由于数十年来数百人收集了数据库中的入口,因此数据值的长度范围很广。虽然我输入的宽度值对于大多数情况来说都足够了,但可能会有更长的特定入口。由于我使用的数据相当关键,我不能忽略这几个案例。我最初的想法是 PdfTable 会自动弯曲一个新行并使单元格更高。但是当我在测试中遇到这个确切的问题时,我注意到文本一直在继续并覆盖下一个单元格。是否有一个简单的解决方法,我可以告诉 PdfTable 自动执行此操作,还是我必须计算字符串中的字母数并为每个长的值分配它?由于我仍然是编程的初学者,因此我非常感谢任何帮助和输入。