开发者

How can I format text with borders and get it printed?

开发者 https://www.devze.com 2023-02-15 05:03 出处:网络
Sorry for my title, I can\'t think of a good one. Anyway. Can someone help me give an idea how to achieve a format like this? what to use? (ex: richtextbox) how to create th开发者_开发知识库e cell bor

Sorry for my title, I can't think of a good one. Anyway. Can someone help me give an idea how to achieve a format like this? what to use? (ex: richtextbox) how to create th开发者_开发知识库e cell borders? and it should also be printable.

How can I format text with borders and get it printed?


Can you just use a DataGridView? Seems a lot easier then trying to maintain consistent column widths.


Have you heard about iTextSharp? You can create tables with itextsharp. But you need to save it as pdf format. So the idea here is create a table format like that and save it as pdf then open it to a webrowser or some kind of a pdf renderer by then you will be able to print it as well.

Here's a simple code for creating table:

    private bool Test(string pdf_file) 
    {
        bool ret = false;
        Document doc = new Document(PageSize.A4);

        try
        {
            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(pdf_file, FileMode.Create));
            doc.Open();

            PdfPTable table = new PdfPTable(3);
            PdfPCell cell = new PdfPCell(new Phrase("Header Column"));
            cell.Colspan = 3;
            cell.HorizontalAlignment = 1; 
            table.AddCell(cell);
            table.AddCell("row1:col1");
            table.AddCell("row1:col2");
            table.AddCell("row1:col3");
            doc.Add(table);

            ret = true;
        }
        catch (DocumentException de)
        {
            MessageBox.Show(de.Message);
        }
        catch (IOException ioe)
        {
            MessageBox.Show(ioe.Message);
        }

        doc.Close();

        if(ret)
            MessageBox.Show("File has been created");

        return ret;
    }

PDF Output:

How can I format text with borders and get it printed?


I think you should Create Local Report (.rdlc) in Report Viewer to do that. Using This the user can extract your data in different format(Excel,PDF and CSV).

Dynamic Report

Using Winform Reports

Regards

0

精彩评论

暂无评论...
验证码 换一张
取 消