Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在itextsharp pdf中隐藏表格单元格可见性_C#_Asp.net_Itextsharp - Fatal编程技术网

C# 如何在itextsharp pdf中隐藏表格单元格可见性

C# 如何在itextsharp pdf中隐藏表格单元格可见性,c#,asp.net,itextsharp,C#,Asp.net,Itextsharp,我有一张固定单元格为2的桌子。我想根据我的条件隐藏表格单元格的可见性。我的情况是 PdfPTable table1 = new PdfPTable(2); table1.SetTotalWidth(new float[] { 200f, 100f}); table1.TotalWidth = 800f;//table size foreach (GridViewRow row in grdtimetable.Rows) { Label lblday = (Label)row.FindC

我有一张固定单元格为2的桌子。我想根据我的条件隐藏表格单元格的可见性。我的情况是

PdfPTable table1 = new PdfPTable(2);
table1.SetTotalWidth(new float[] { 200f, 100f});
table1.TotalWidth = 800f;//table size

foreach (GridViewRow row in grdtimetable.Rows)
{
    Label lblday = (Label)row.FindControl("lbltopicvalue");
    Label lblperiod1 = (Label)row.FindControl("lblperiod1");

    table1.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
    table1.AddCell(new Phrase("Days", time550));

    if(lblperiod1 .Text!="NULL"||lblperiod1 .Text!="")
    {
        table1.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
        table1.AddCell(new Phrase(""+lblperiod1 .text+"", time550));
    }
    else
    {
        //Here I want to make this cell visibility hidden
    }
}


可能吗?如果是,请帮助我有几种方法。我将举例说明几个

如果要保持其他表格单元格的位置不变,即不向左移动,可以简单地添加空单元格:

doc.Add(new Paragraph("Option 1:"));
PdfPTable table = new PdfPTable(5);
table.SpacingBefore = 10;
for (int i = 1; i <= 5; i++)
{
    if (i == 2 || i == 3)
    {
        // Add an empty cell
        PdfPCell empty = new PdfPCell();
        empty.Border = PdfPCell.NO_BORDER;
        table.AddCell(empty);
    }
    else
    {
        table.AddCell(new PdfPCell(new Phrase("Cell " + i)));
    }
}
doc.Add(table);
doc.Add(新段落(“选项1”);
PdfPTable=新的PdfPTable(5);
表1.1:间隔时间前=10;

对于(inti=1;i有几种方法可以做到这一点。我将举例说明几种方法

如果要保持其他表格单元格的位置不变,即不向左移动,可以简单地添加空单元格:

doc.Add(new Paragraph("Option 1:"));
PdfPTable table = new PdfPTable(5);
table.SpacingBefore = 10;
for (int i = 1; i <= 5; i++)
{
    if (i == 2 || i == 3)
    {
        // Add an empty cell
        PdfPCell empty = new PdfPCell();
        empty.Border = PdfPCell.NO_BORDER;
        table.AddCell(empty);
    }
    else
    {
        table.AddCell(new PdfPCell(new Phrase("Cell " + i)));
    }
}
doc.Add(table);
doc.Add(新段落(“选项1”);
PdfPTable=新的PdfPTable(5);
表1.1:间隔时间前=10;

对于(int i=1;i如何定义隐藏?添加一个没有边框的空单元格是否足够?@rhens,我不明白你的意思。实际上,我的要求是,我正在尝试生成一个时间表。我已将列数设置为5。但在某些特定情况下,周期数将为2,那么其他3个单元格应隐藏。等待@Bruno Lowegi..假设您想隐藏单元格2和3,您想要哪一个?如果没有,请澄清您的问题。@rhens,选项2或3。还有一个条件。如果2为空,则剩余部分也将为空(3、4和5)你如何定义隐藏?添加一个没有边框的空单元格就足够了吗?@rhens,我不明白你的意思。实际上,我的要求是,实际上我正在尝试生成一个时间表。我将列数设置为5。但在某些特定情况下,周期数将为2,那么其他3个单元格应该隐藏。等待@Bruno Lowegi。。假设您想隐藏单元格2和3,您想要哪一个?如果没有,请澄清您的问题。@rhens,选项2或3。还有一个条件。如果2为空,剩余部分也将为空(3、4和5)
doc.Add(new Paragraph("Option 3:"));
// Determine the number of empty cells before hand
int emptycellsCounted = 2;
PdfPTable table3 = new PdfPTable(5 - emptycellsCounted);
table3.SpacingBefore = 10;
for (int i = 1; i <= 5; i++)
{
    if (i == 2 || i == 3)
    {
        // Do nothing
    }
    else
    {
        table3.AddCell(new PdfPCell(new Phrase("Cell " + i)));
    }
}
doc.Add(table3);

doc.Close();