在iTextSharp的多个表列排列 [英] Multiple Table Column alignment in iTextsharp

查看:297
本文介绍了在iTextSharp的多个表列排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个表,其中每列有它自己的校准如下所示。我如何完成它的列级比在细胞水平上?

I am creating a table where each column has its own alignment as shown below. How do I accomplish it at column level than at cell level?

推荐答案

的iText和iTextSharp的不支持列样式和格式。要做到这一点的唯一方法是,你正在做的现在,通过细胞的细胞。

iText and iTextSharp don't support column styles and formatting. The only way to do this is as you are doing currently, cell by cell.

修改

最简单的解决方法是创建一个设置公共属性的辅助方法。这些可以通过扩展方法,或只是普通的静态方法来进行。我没有一个C#IDE在我面前,让我的例子code以下是在VB,但应该很容易转化。

The easiest work around is to create helper methods that set your common properties. These can either be done through extension methods or just regular static methods. I don't have a C# IDE in front of me so my sample code below is in VB but should translate fairly easily.

您可以创建几个快捷的方式为每个对齐方式:

You can create a couple of quick methods for each alignment:

Public Shared Function CreateLeftAlignedCell(ByVal text As String) As PdfPCell
    Return New PdfPCell(New Phrase(text)) With {.HorizontalAlignment = PdfPCell.ALIGN_LEFT}
End Function
Public Shared Function CreateRightAlignedCell(ByVal text As String) As PdfPCell
    Return New PdfPCell(New Phrase(text)) With {.HorizontalAlignment = PdfPCell.ALIGN_RIGHT}
End Function
Public Shared Function CreateCenterAlignedCell(ByVal text As String) As PdfPCell
    Return New PdfPCell(New Phrase(text)) With {.HorizontalAlignment = PdfPCell.ALIGN_CENTER}
End Function

或者只是一个单一的一个,你必须通过在已知常量之一:

Or just a single one that you have to pass in one of the known constants:

Public Shared Function CreatePdfPCell(ByVal text As String, ByVal align As Integer) As PdfPCell
    Return New PdfPCell(New Phrase(text)) With {.HorizontalAlignment = align}
End Function

然后,你可以做到以下几点:

Then you can just do the following:

Dim T As New PdfPTable(3)
T.AddCell(CreateCenterAlignedCell("Hello"))

这篇关于在iTextSharp的多个表列排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆