3
I have a problem and I can’t find a solution, I am using itextesharp in a windowsfroms application, I created a table with 7 cells and I would like to align some right and others centralized. unfortunately I am only able to align either all the cells to the right or to the left. through the table.DefaultCell.Horizontalalignment = 0; I’ll post the code. I would like to thank anyone who can help, because I really need to finish this report.
PdfPTable tabela = new PdfPTable(7);
PdfPCell celula = new PdfPCell();
tabela.TotalWidth = 790f;
// celula.HorizontalAlignment = 1;
tabela.DefaultCell.HorizontalAlignment = 0;
tabela.LockedWidth = true;
float[] widths = new float[] { 16F, 40f,45F,60F,15f, 15f, 15f };
tabela.SetWidths(widths);
tabela.HorizontalAlignment = 0;
celula.HorizontalAlignment = 0;
strSql= " ";
con = new SqlConnection(strcon);
SqlCommand cmd2 = new SqlCommand(strSql, con);
cmd2.Parameters.AddWithValue("@DataI", DateTime.Parse(mtbDtInicial.Text));
cmd2.Parameters.AddWithValue("@DataF", DateTime.Parse(mtbDtFinal.Text));
cmd2.Parameters.AddWithValue("@ifd", emn1);
con.Open();
SqlDataReader ler = cmd2.ExecuteReader();
while (ler.Read())
{
tabela.AddCell (ler[4].ToString()); //conta a direita
tabela.AddCell(ler[0].ToString());//título a direita
tabela.AddCell(ler[1].ToString());//subtitulo a direita
tabela.AddCell(ler[2].ToString());//descr a direita
tabela.AddCell(ler[6].ToString());//valor centralizado
tabela.AddCell(ler[7].ToString());//perce centralizado
tabela.AddCell(ler[8].ToString());//desp centralizado
}
document2.Add(tabela);