-1
我嘗試使用itextsharp創建PDF時嘗試將「Amount」的DataGrid列的某一列對齊到右側,但無法這樣做。所有列左對齊,一些列應左對齊,最後一列應右對齊。請幫忙從Win表單在iTextSharp中將列對齊更改爲「右」
以下是代碼。
PdfPTable pdfTable = new PdfPTable(dataGridView1.ColumnCount);
pdfTable.SetWidths(new float[] { 5f, 10f, 10f, 7f, 9f });
pdfTable.DefaultCell.Padding = 3;
pdfTable.WidthPercentage = 90;
pdfTable.HorizontalAlignment = Element.ALIGN_LEFT;
pdfTable.DefaultCell.BorderWidth = 1;
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText, fontTitle2));
cell.BackgroundColor = new iTextSharp.text.BaseColor(240, 240, 240);
cell.HorizontalAlignment = Element.ALIGN_CENTER;
pdfTable.AddCell(cell);
}
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
pdfTable.AddCell(new Phrase(cell.Value.ToString(), fontTitle));
}
}
解決了這個問題,但是你可以幫忙用if循環代碼 – 2015-02-12 16:59:08