i am sending u my complete code it will be difficult to understand my requirement is to insert a table which is having 33 coloumns in it and 25 rows which won't fit into single slide so i am splitingthe table and adding it to slide . please tell me whats wrong in this
private void SetTableInPowerPoint(Aspose.Slides.Presentation pres, Aspose.Slides.Slide slide, DataTable dtNames, DataTable dtYears, int coloumnIndex, int rowIndex, int currentHeight, int slideUseableWidth, int left, int top, int useableHeight, int expectedTablHeight)
{
bool isRowHeightSet = false;
if ((currentHeight > useableHeight - 200 || rowIndex != 0) && (top > useableHeight - 100))
{
pres.AddEmptySlide();
slide = pres.Slides[pres.Slides.Count - 1];
slide.FollowMasterBackground = false;
slide.FollowMasterScheme = false;
top = 1000;
}
if (coloumnIndex == dtNames.Columns.Count + dtYears.Columns.Count - 1)
coloumnIndex = coloumnIndex + 1;
currentHeight = top;
Aspose.Slides.Table dtSlide;
dtSlide = slide.Shapes.AddTable(left, top, 850, 20, 1, 1);
double tempWidth = 0;
dtSlide.SetBorders(1.00, System.Drawing.Color.Black);
int colNumber = 0;
for (int i = 0; i < dtNames.Columns.Count; i++)
{
if (i != 0)
dtSlide.AddColumn();
Aspose.Slides.Cell cell = dtSlide.GetCell(i, 0);
tempWidth = tempWidth + cell.Width;
cell.TextFrame.Text = dtNames.Columns
.ColumnName;
cell.TextFrame.FitTextToShape();
cell.TextFrame.WrapText = true;
cell.TextFrame.Paragraphs[0].Portions[0].FontBold = true;
cell.TextFrame.Paragraphs[0].Alignment = TextAlignment.Left;
cell.TextFrame.Paragraphs[0].HasBullet = 0;
cell.FillFormat.Type = FillType.Solid;
cell.FillFormat.BackColor = SystemColors.InactiveCaption;
cell.TextFrame .FillFormat.BackColor = SystemColors.InactiveCaption;
if (isRowHeightSet == false)
{
currentHeight = currentHeight + cell.Height;
isRowHeightSet = true;
}
}
if (coloumnIndex != 0)
colNumber = coloumnIndex - dtNames.Columns.Count;
int cellNumber = 0;
for (int i = colNumber; i < dtYears.Columns.Count; i++)
{
dtSlide.AddColumn();
Aspose.Slides.Cell cell = dtSlide.GetCell(cellNumber + dtNames.Columns.Count, 0);
cell.TextFrame.FillFormat.BackColor = SystemColors.InactiveCaption;
cell.TextFrame.Text = dtYears.Columns
.ColumnName;
cell.TextFrame.FitShapeToText = true;
cell.TextFrame.Paragraphs[0].Portions[0].FontBold = true;
cell.TextFrame.Paragraphs[0].Alignment = TextAlignment.Right;
cell.TextFrame.Paragraphs[0].HasBullet = 0;
cell.FillFormat.BackColor = System.Drawing.SystemColors.InactiveCaption;
tempWidth = tempWidth + cell.Width;
cellNumber++;
if (tempWidth > slideUseableWidth)
break;
}
if (currentHeight > useableHeight - 200)
{
dtSlide.Height = 0;
}
for (int i = rowIndex; i < dtNames.Rows.Count; i++)
{
isRowHeightSet = false;
tempWidth = 0;
cellNumber = 0;
dtSlide.AddRow();
if (coloumnIndex != 0)
{
for (int l = 0; l < dtNames.Columns.Count; l++)
{
Aspose.Slides.Cell cell = dtSlide.GetCell(l, i - rowIndex + 1);
cell.TextFrame.Paragraphs[0].Portions[0].FontBold = false;
tempWidth = tempWidth + cell.Width;
cell.TextFrame.FitTextToShape();
cell.TextFrame.Text = dtNames.Rows
[l].ToString();
cell.TextFrame.Paragraphs[0].Portions[0].FontBold = false;
cell.TextFrame.Paragraphs[0].HasBullet = 0;
if (l == 0)
{
currentHeight = dtSlide.Y + dtSlide.Height;
}
}
}
for (int j = coloumnIndex; j < (dtNames.Columns.Count + dtYears.Columns.Count); j++)
{
if (coloumnIndex == 0 && i < dtNames.Rows.Count)
{
Aspose.Slides.Cell cell = dtSlide.GetCell(j, i + 1 - rowIndex);
tempWidth = tempWidth + cell.Width;
cell.TextFrame.FitTextToShape();
if (j < dtNames.Columns.Count)
cell.TextFrame.Text = dtNames.Rows
[j].ToString();
else
{
cell.TextFrame.Text = dtYears.Rows
[j - dtNames.Columns.Count].ToString();
cell.TextFrame.Paragraphs[0].Alignment = TextAlignment.Right;
}
cell.TextFrame.Paragraphs[0].Portions[0].FontBold = false;
cell.TextFrame.Paragraphs[0].HasBullet = 0;
if (isRowHeightSet == false)
{
currentHeight = dtSlide.Y + dtSlide.Height;
isRowHeightSet = true;
}
if (tempWidth > slideUseableWidth)
{
if (i == dtNames.Rows.Count - 1 && j != dtNames.Columns.Count + dtYears.Columns.Count - 2)
{
coloumnIndex = j + 1;
rowIndex = 0;
}
else if (i == dtNames.Rows.Count - 1 && j == dtNames.Columns.Count + dtYears.Columns.Count - 2)
{
coloumnIndex = j;
rowIndex = 0;
}
break;
}
}
else
{
Aspose.Slides.Cell cell = dtSlide.GetCell(cellNumber + dtNames.Columns.Count, i - rowIndex + 1);
tempWidth = tempWidth + cell.Width;
cell.TextFrame.FitTextToShape();
cell.TextFrame.Text = dtYears.Rows
[j - dtNames.Columns.Count].ToString();
cell.TextFrame.Paragraphs[0].Portions[0].FontBold = false;
cell.TextFrame.Paragraphs[0].HasBullet = 0;
cell.TextFrame.Paragraphs[0].Alignment = TextAlignment.Right;
if (isRowHeightSet == false)
{
currentHeight = dtSlide.Y + dtSlide.Height;
isRowHeightSet = true;
}
cellNumber++;
if (tempWidth > slideUseableWidth)
{
if (i == dtNames.Rows.Count - 1 && j != dtNames.Columns.Count + dtYears.Columns.Count - 2)
coloumnIndex = j + 1;
else if (i == dtNames.Rows.Count - 1 && j == dtNames.Columns.Count + dtYears.Columns.Count - 2)
coloumnIndex = j;
break; ;
}
else if (tempWidth < slideUseableWidth && (i == dtNames.Rows.Count - 1))
{
coloumnIndex = j;
}
}
}
if (currentHeight > useableHeight - 200)
{
if (i != dtNames.Rows.Count - 1)
rowIndex = i+1;
else
{
rowIndex = 0;
}
break;
}
if (i == dtNames.Rows.Count - 1)
rowIndex = 0;
}
if ((coloumnIndex != 0 && coloumnIndex < (dtNames.Columns.Count + dtYears.Columns.Count - 1)) || rowIndex != 0)
{
SetTableInPowerPoint(pres, slide, dtNames, dtYears, coloumnIndex, rowIndex, currentHeight, slideUseableWidth, left, dtSlide.Y + dtSlide.Height + 100, useableHeight, dtSlide.Height);
}
}