Mon May 14, 2018 2:36 pm
Sample Code:
public static MemoryStream ReplaceTableTags(PresentationInfo PresentationDocument, PresentationDocumentTables DocumentTables, FileFormat PresentationFormat)
{
Presentation PresentationFile = new Presentation(new MemoryStream(PresentationDocument.FileStream), PresentationFormat);
if (DocumentTables != null)
{
for (int i = 0; i < PresentationFile.Slides.Count; i++)
{
foreach (PresentationTable TableSubstitution in DocumentTables.Tables)
{
ITable Table = GetTableFromShapes(TableSubstitution.TableName, PresentationFile.Slides[i].Shapes);
if (Table != null)
{
foreach (TableCellContext CellContext in TableSubstitution.CellContext)
{
if (CellContext.RowIndex >= 0 && CellContext.ColumnIndex >= 0 && Table.TableRows.Count - 1 >= CellContext.RowIndex && Table.ColumnsList.Count - 1 >= CellContext.ColumnIndex)
{
List<TableCellContext> Duplicates = TableSubstitution.CellContext.Where(cell => cell.RowIndex == CellContext.RowIndex && cell.ColumnIndex == CellContext.ColumnIndex).ToList();
if (Duplicates.Count > 1)
{
double ColumnWidth = Table[CellContext.ColumnIndex, CellContext.RowIndex].Width / Duplicates.Count;
double[] ColumnWidths = new double[Duplicates.Count];
for (int z = 0; z < Duplicates.Count; z++)
ColumnWidths[z] = ColumnWidth;
double[] ColumnHeights = new double[] { (float)Table[CellContext.ColumnIndex, CellContext.RowIndex].Height };
ITable CellTable = PresentationFile.Slides[i].Shapes.AppendTable((float)Table[CellContext.ColumnIndex, CellContext.RowIndex].Width,
(float)Table[CellContext.ColumnIndex, CellContext.RowIndex].Height, ColumnWidths, ColumnHeights);
CellTable.SetTableBorder(TableBorderType.None, 0, Color.Transparent);
for (int a = 0; a < Duplicates.Count(); a++)
{
CellTable[a, 0].TextFrame.Text = Duplicates[a].Value;
//Can remove the below line if text alignment is specified in substitution data
CellTable[a, 0].TextFrame.IsCentered = Table[CellContext.ColumnIndex, CellContext.RowIndex].TextFrame.IsCentered;
CellTable[a, 0].FillFormat.SolidColor.Color = Color.Transparent;
ApplyCellStyle(Duplicates[a], CellTable[a, 0]);
//How to send this in substitution data?
/*CellTable[a, 0].BorderRight.Width = 1.0;
CellTable[a, 0].BorderRight.Style = TextLineStyle.Single;
CellTable[a, 0].BorderRight.FillType = FillFormatType.Solid;
CellTable[a, 0].BorderRight.DashStyle = LineDashStyleType.Solid;*/
}
CellTable.Left = Table.Left + (float)Table[CellContext.ColumnIndex, CellContext.RowIndex].OffsetX;
CellTable.Top = Table.Top + (float)Table[CellContext.ColumnIndex, CellContext.RowIndex].OffsetY;
TableSubstitution.CellContext.Where(Context => Context.RowIndex == CellContext.RowIndex && Context.ColumnIndex == CellContext.ColumnIndex).ToList().ForEach(Context => { Context.ColumnIndex = -1; Context.RowIndex = -1; });
continue;
}
Table[CellContext.ColumnIndex, CellContext.RowIndex].TextFrame.Text = CellContext.Value;
ApplyCellStyle(CellContext, Table[CellContext.ColumnIndex, CellContext.RowIndex]);
}
}
}
}
}
}
MemoryStream PresentationData = new MemoryStream();
//PresentationFile.SlideSize.Size = PresentationFile.SlideSize.SizeOfPx;
// PresentationFile.SlideSize.SizeOfPx = PresentationFile.SlideSize.SizeOfPx;
//PresentationFile.SlideSize.Type = PresentationFile.SlideSize.Type;
//PresentationFile.SetPageSize(16.0F, 9.0F, true);
PresentationFile.SaveToFile(PresentationData, PresentationFormat);
//PresentationFile.SlideSize.Type = SlideSizeType.
return PresentationData;
}
Login to view the files attached to this post.