【发布时间】:2015-10-22 19:07:59
【问题描述】:
我有下一个问题:
我需要合并此表中具有相同值的行:
这个表在一个GridView中,我实现了合并那些行的方法
private void AgruparGridView(GridViewRowCollection rows, int indiceInicial, int totalCeldasAgrupar)
{
//Si no hay celdas a agrupar no realiza ninguna acción
if (totalCeldasAgrupar == 0)
return;
int i, count = 1;
ArrayList lst = new ArrayList();
// Los elementos del gridview son llenados en la lista.
lst.Add(rows[0]);
var ctrl = rows[0].Cells[indiceInicial];
//Recorrer los registros que se tengan para agrupar
for (i = 1; i < rows.Count; i++)
{
TableCell nextCell = rows[i].Cells[indiceInicial];
if (ctrl.Text == nextCell.Text)
{
count++;
nextCell.Visible = false;
lst.Add(rows[i]);
}
else
{
if (count > 1)
{
ctrl.RowSpan = count;
AgruparGridView(new GridViewRowCollection(lst), indiceInicial + 1, totalCeldasAgrupar - 1);
}
count = 1;
lst.Clear();
ctrl = rows[i].Cells[indiceInicial];
lst.Add(rows[i]);
}
}
if (count > 1)
{
ctrl.RowSpan = count;
AgruparGridView(new GridViewRowCollection(lst), indiceInicial + 1, totalCeldasAgrupar - 1);
}
count = 1;
lst.Clear();
}
我需要使用 iTextSharp 在 PDF 报告上实现相同的结果,但我不知道这个过程。
构建这个部分的代码片段是这样的:
public PdfPTable Tablas(int TipoSeccion, int TipoDoc, int ClaveEntidad, int ClaveSubSis, string descripcion)
{
PDFEvents oPDFEvents = new PDFEvents();
string sError = string.Empty;
int columns = 1;
int i = 0;
DataSet _DatosTabla = null;
PdfPTable Table;
PdfPCell CeldaNoBorde = new PdfPCell(CeldasSinBorde("", 1, 1, 4, 255, 255, 255));
#region PerfilesDOCENTE
#region Tipo3
if (TipoSeccion == 3)
{
columns = 3;
Table = new PdfPTable(columns);
Table.WidthPercentage = 80;
float[] widhts = new float[] { 15, 50 };
//Header Superior
if (this.TipoSeccionOriginal == 3 || this.TipoSeccionOriginal==0)
{
Table.AddCell(Celdas("ASIGNATURAS POR EXAMEN DISCIPLINAR PARA FUNCIONES DOCENTES", 2, 3, 8, 238, 233, 233));
Table.AddCell(Celdas("Área disciplinar", 3, 1, 10, 238, 233, 233));
Table.AddCell(Celdas("Asignatura", 3, 1, 10, 238, 233, 233));
Table.AddCell(Celdas("Evaluación Disciplinar", 3, 1, 10, 238, 233, 233));
_DatosTabla = DameDatosTablaPerfilesTelebach(ClaveEntidad, ClaveSubSis);
}
else
{
Table.AddCell(Celdas("ASIGNATURAS A CONCURSO PARA FUNCIONES TÉCNICO DOCENTES", 1, 2, 8, 238, 233, 233));
Table.AddCell(Celdas("Evaluación", 2, 1, 10, 238, 233, 233));
Table.AddCell(Celdas("Asignaturas", 2, 1, 10, 238, 233, 233));
_DatosTabla = DameDatosTablaPerfiles(TipoDoc, ClaveEntidad, ClaveSubSis, true);
}
if (_DatosTabla != null)
{
while (i < _DatosTabla.Tables[0].Rows.Count)
{
Table.AddCell(oPDFEvents.FontPhrase(_DatosTabla.Tables[0].Rows[i][0].ToString(), 10));
Table.AddCell(oPDFEvents.FontPhrase(_DatosTabla.Tables[0].Rows[i][1].ToString(), 10));
Table.AddCell(oPDFEvents.FontPhrase(_DatosTabla.Tables[0].Rows[i][2].ToString(), 10));
i = i + 1;
}
}
return Table;
}
我的结果是这样的
对不起我的英语不好!! 感谢您的关注!
【问题讨论】:
-
当您说合并具有相同值的行时,您是指将不同行的单元格合并为一个单元格,即rowspan?在屏幕截图中,带有文本“Matemáticas y Ciencias Experimientales”的单元格的行跨度为 14。
-
是的,在屏幕截图中是在 aspx 中,但我不知道如何使用 iTextSharp 导出到 PDF,因为这是我工作中导出 pdf 的工具
-
@MarcoLuna 您在上面发布的代码仅用于合并
GridView控件的行。您需要发布与 iTextSharp 相关的代码。您如何将行导出为 PDF,到目前为止您为在 iTextSharp 中实现行跨度所做的尝试是什么? -
我所知道的是该方法使用 PdfPTable 来构建文档,它正在重新加载我用来填充 GridView 的相同数据集,我编辑了这个问题以便更好地理解
标签: c# asp.net pdf itextsharp