0

I am reading data from an XLSX file using EPPlus and then, converting it to PDF using MigraDoc. But the date fields show some double values.

For e.g. : 2014-06-17 19.25.14 becomes 41807.8091898148 in the PDF.

_book = _package.Workbook;
_sheet = _book.Worksheets[1];
Table _table;
for (int row = 5; row <= end.Row; row++)
{
   Row _row = _table.AddRow();
   for ((int col = 1; col <= end.Column; col++)
      _row.Cells[col - 1].AddParagraph(_sheet.Cells[row, col].Value.ToString());
}
 _pdfRenderer.RenderDocument();

How do I correct it?

harsha
  • 103
  • 2
  • 8
  • 1
    `_sheet.Cells[row, col].Value` obviously does not return a DateTime for your date columns. This is not a MigraDoc problem, it's a problem with your XLSX file or with EPPlus - or with the usage of EPPlus (is there a way to access cell type with EPPlus?). – I liked the old Stack Overflow Jun 20 '14 at 10:45
  • Yes, we can access cell type with EPPlus, but not Migradoc. Only the `ToString()` function can be used with `AddParagraph()`. However, the biggest confusion is that in some of the PDFs, the formatting is fine - no issues whatsoever. – harsha Jun 23 '14 at 04:58
  • 1
    You pass a string to MigraDoc - it's up to you to format the cell data properly to get the correct text. You call `ToString()` for the cell returned by EPPlus, so you cannot blame MigraDoc if EPPlus' ToString function does not give you the string you expect. Let EPPlus give you a DateTime object and call ToString for that and you will see a correct date in your PDF file. – I liked the old Stack Overflow Jun 23 '14 at 21:59
  • I got the answer. Converted the string value to double `Convert.ToDouble()` and the resultant double value to date using `DateTime.FromOADate()`. Thanks anyway – harsha Jul 09 '14 at 05:58

0 Answers0