Olá galera.
Minha duvida é o seguinte, tem como formatar um relatório em pdf que foi gerado de um gridview.
Estou desenvolvendo uma aplicação c# Desktop, em um determinado formulário estou gerando um relatório em pdf com os dados do gridview, mas as colunas e o conteúdo estão todos desconfigurados.
Alguém poderia me ajudar a configurar esse arquivo pdf ?
Abaixo o código que utilizo para gerar o arquivo.
private void btnrelatorio_Click(object sender, EventArgs e)
{
string pdf = "Contas_a_Pagas.pdf";
Document document = new Document();
try
{
PdfWriter whiter = PdfWriter.GetInstance(document, new FileStream(pdf, FileMode.Create));
document.Open();
PdfPTable aTable = new PdfPTable(10);
PdfPCell cell = new PdfPCell(new Phrase("Contas Pagas - Relatório - " + DateTime.Now.ToString()));
cell.Colspan = 10;
cell.HorizontalAlignment = 1;
aTable.AddCell(cell);
aTable.AddCell("Id");
aTable.AddCell("Fornecedor");
aTable.AddCell("Banco");
aTable.AddCell("Vencimento");
aTable.AddCell("Tipo");
aTable.AddCell("Numero");
aTable.AddCell("Valor");
aTable.AddCell("Historico");
aTable.AddCell("Cadastrada");
aTable.AddCell("Pgto");
for (int i = 0; i < dgvdados.RowCount - 1; i++)
{
aTable.AddCell(dgvdados[0, i].Value.ToString());
aTable.AddCell(dgvdados[1, i].Value.ToString());
aTable.AddCell(dgvdados[2, i].Value.ToString());
aTable.AddCell(dgvdados[3, i].Value.ToString());
aTable.AddCell(dgvdados[4, i].Value.ToString());
aTable.AddCell(dgvdados[5, i].Value.ToString());
aTable.AddCell(dgvdados[6, i].Value.ToString());
aTable.AddCell(dgvdados[7, i].Value.ToString());
aTable.AddCell(dgvdados[8, i].Value.ToString());
aTable.AddCell(dgvdados[9, i].Value.ToString());
aTable.ToString();
}
document.Add(aTable);
}
catch (DocumentException s)
{
throw s;
}
catch (IOException o)
{
throw o;
}
document.Close();
}