Goran Bibic Ответов: 1

Настройка типа столбца ITEXTSHARP C#?


I have problem with output result...
Column have value 16.2.2018 00:00:00
 
I need value  16.2.2018
 
Sql column type  is DATETIME

In another column have type DATE and same problem
 
Need help


Что я уже пробовал:

private void button2_Click(object sender, EventArgs e) //pdf print button  
        {  
            //Creating iTextSharp Table from the DataTable data  
            //Console.WriteLine(drzaveDataGridView.ColumnCount); test za itext sharp  
            PdfPTable pdfTable = new PdfPTable(mktestprobaDataGridView.ColumnCount);  
            pdfTable.DefaultCell.Padding = 3;  
            pdfTable.WidthPercentage = 100;  
            pdfTable.HorizontalAlignment = Element.ALIGN_LEFT;  
            pdfTable.DefaultCell.BorderWidth = 1;  
            float[] sirina = new float[] { 20f, 25f, 45f, 56f, 43f };  
            pdfTable.SetWidths(sirina);  
            BaseFont bfCalibri = BaseFont.CreateFont("c:\\windows\\fonts\\calibri.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);  
            iTextSharp.text.Font calibri = new iTextSharp.text.Font(bfCalibri, 8);  
  
  
            //Adding Header row  
            foreach (DataGridViewColumn column in mktestprobaDataGridView.Columns)  
            {  
                PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText));  
                //cell.BackgroundColor = new iTextSharp.text.Color(240, 240, 240);  
                pdfTable.AddCell(cell);  
            }  
  
            //Adding DataRow  
            foreach (DataGridViewRow row in mktestprobaDataGridView.Rows)  
            {  
  
                foreach (DataGridViewCell cell in row.Cells)  
                {  
                    pdfTable.AddCell(cell.Value.ToString());  
                }  
            }  
  
            //Exporting to PDF  
  
            string folderPath = "C:\\PDFs\\";  
            if (!Directory.Exists(folderPath))  
            {  
                Directory.CreateDirectory(folderPath);  
            }  
            using (FileStream stream = new FileStream(folderPath + "Drzave.pdf", FileMode.Create))  
            {  
                iTextSharp.text.Font calibriTitle = new iTextSharp.text.Font(bfCalibri, 18);  
                iTextSharp.text.Font calibriSubTitle = new iTextSharp.text.Font(bfCalibri, 14);  
  
                Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);  
                PdfWriter.GetInstance(pdfDoc, stream);  
                pdfDoc.Open();  
               // pdfDoc.Add(new Paragraph(korisnik_programa));  
              //  pdfDoc.Add(new Paragraph(adresa));  
                pdfDoc.Add(pdfTable);  
                pdfDoc.Close();  
                stream.Close();  
                System.Diagnostics.Process.Start(folderPath + "Drzave.pdf");  
            }  
        }  

1 Ответов

Рейтинг:
0

Richard MacCutchan

Используйте строку формата, чтобы определить, какие значения следует печатать, см. значение datetime.Метод ToString (String) (System)[^].


Goran Bibic

Что нужно изменить в моем коде? я смотрю пример, но не понимаю...

Я попробую это сделать



строка yourDateString = testtableDataGridView.Rows[строка][dataGridViewTextBoxColumn12].ToString("ДД/ММ/гггг");

Ошибка приклада-это [строка]

Ошибка CS1503 Аргумент 1: не удается преобразовать из 'System.Окна.Формы.DataGridViewRow' to 'int'

Richard MacCutchan

Видеть Класс DataGridViewCell[^] для правильного способа доступа к ячейкам DataGridView.