I have a Datagridview where the first column displays the date values .Now i need to export that into pdf but my pdf file consists of both date and time values in the same column that i dont want.
我有一个Datagridview,其中第一列显示日期值。现在我需要将其导出为pdf,但我的pdf文件包含我不想要的同一列中的日期和时间值。
Here is the code..
这是代码..
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
for (int k = 0; k < dataGridView1.Columns.Count; k++)
{
if (dataGridView1[k, i].Value != null)
{
pdfTable.AddCell(new Phrase(dataGridView1[k, i].Value.ToString(), fontTable));
}
}
}
In the following line .
在以下行中。
pdfTable.AddCell(new Phrase(dataGridView1[k, i].Value.ToString(), fontTable));
On debugging i am getting date and time both for my date column .
在调试时,我获得了日期列的日期和时间。
How to solve this ..?
怎么解决这个..?
1 个解决方案
#1
0
Replace
pdfTable.AddCell(new Phrase(dataGridView1[k, i].Value.ToString(), fontTable));
with
if(k==0)
{
pdfTable.AddCell(new Phrase(dataGridView1[k, i].Value.ToString().Substring(0, 12), fontTable));
}else
{
pdfTable.AddCell(new Phrase(dataGridView1[k, i].Value.ToString(), fontTable));
}
i hope your problem will be solved
我希望你的问题能够得到解决
#1
0
Replace
pdfTable.AddCell(new Phrase(dataGridView1[k, i].Value.ToString(), fontTable));
with
if(k==0)
{
pdfTable.AddCell(new Phrase(dataGridView1[k, i].Value.ToString().Substring(0, 12), fontTable));
}else
{
pdfTable.AddCell(new Phrase(dataGridView1[k, i].Value.ToString(), fontTable));
}
i hope your problem will be solved
我希望你的问题能够得到解决