I'm trying to cutoff the time portion of my data in the pdf printout. The table it prints is from a datagridview table and is the first column called Date (column[0]). Since removing the time out of the data has proven to be such a pain, I wondered if there was a way to just cut the data out of the column. I tried a fixed width and no text wrap but it still wraps the time underneath it. Below is the current code.
private void run_btn_Click(object sender, EventArgs e)
{
SaveFileDialog svg = new SaveFileDialog();
svg.Filter = "PDF File|*.pdf";
svg.ShowDialog();
using (FileStream stream = new FileStream(svg.FileName, FileMode.Create))
{
Document doc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(doc, stream);
doc.Open();
Paragraph paragraph = new Paragraph("" + DateTime.Now.ToShortDateString() +"\n\n");
doc.Add(paragraph);
PdfPTable table = new PdfPTable(CK_QA_DataDataGridView.Columns.Count);
table.DefaultCell.Padding = 5;
table.WidthPercentage = 95;
table.HorizontalAlignment = Element.ALIGN_CENTER;
table.DefaultCell.BorderWidth = 1;
//Adding Header row
foreach (DataGridViewColumn column in CK_QA_DataDataGridView.Columns)
{
PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText));
cell.BackgroundColor = new iTextSharp.text.BaseColor(240, 240, 240);
table.AddCell(cell);
}
//Adding DataRow
foreach (DataGridViewRow row in CK_QA_DataDataGridView.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
table.AddCell(cell.Value.ToString());
}
}
//Add Table
doc.Add(table);
doc.Close();
stream.Close();
Aucun commentaire:
Enregistrer un commentaire