AddTable

ShapeCollection.AddTable метод

Создает новую таблицу и добавляет ее в конец коллекции.

public ITable AddTable(float x, float y, double[] columnWidths, double[] rowHeights)
ПараметрТипОписание
xSingleX-координата для левой стороны рамки объекта.
ySingleY-координата для верхней стороны рамки объекта.
columnWidthsDouble[]Массив дробных чисел, представляющий ширины столбцов в таблице.
rowHeightsDouble[]Массив дробных чисел, представляющий высоты строк в таблице.

Возвращаемое значение

Созданный объект Table.

Примеры

Следующие примеры показывают, как добавить таблицу в презентацию PowerPoint.

[C#]
// Создание экземпляра класса Presentation, который представляет файл PPTX
using (Presentation pres = new Presentation()){
	// Доступ к первому слайду
	ISlide sld = pres.Slides[0];
	// Определение столбцов с ширинами и строк с высотами
	double[] dblCols = { 50, 50, 50 };
	double[] dblRows = { 50, 30, 30, 30, 30 };
	// Добавление формы таблицы на слайд
	ITable tbl = sld.Shapes.AddTable(100, 50, dblCols, dblRows);
	// Установка формата рамки для каждой ячейки
	for (int row = 0; row < tbl.Rows.Count; row++)
	{
		for (int cell = 0; cell < tbl.Rows[row].Count; cell++)
		{
			tbl.Rows[row][cell].CellFormat.BorderTop.FillFormat.FillType = FillType.Solid;
			tbl.Rows[row][cell].CellFormat.BorderTop.FillFormat.SolidFillColor.Color = Color.Red;
			tbl.Rows[row][cell].CellFormat.BorderTop.Width = 5;
			tbl.Rows[row][cell].CellFormat.BorderBottom.FillFormat.FillType = (FillType.Solid);
			tbl.Rows[row][cell].CellFormat.BorderBottom.FillFormat.SolidFillColor.Color= Color.Red;
			tbl.Rows[row][cell].CellFormat.BorderBottom.Width =5;
			tbl.Rows[row][cell].CellFormat.BorderLeft.FillFormat.FillType = FillType.Solid;
			tbl.Rows[row][cell].CellFormat.BorderLeft.FillFormat.SolidFillColor.Color =Color.Red;
			tbl.Rows[row][cell].CellFormat.BorderLeft.Width = 5;
			tbl.Rows[row][cell].CellFormat.BorderRight.FillFormat.FillType = FillType.Solid;
			tbl.Rows[row][cell].CellFormat.BorderRight.FillFormat.SolidFillColor.Color = Color.Red;
			tbl.Rows[row][cell].CellFormat.BorderRight.Width = 5;
		}
	}
	// Объединение ячеек 1 и 2 строки 1
	tbl.MergeCells(tbl.Rows[0][0], tbl.Rows[1][1], false);
	// Добавление текста в объединенную ячейку
	tbl.Rows[0][0].TextFrame.Text = "Объединенные ячейки";
	// Сохранение PPTX на диск
	pres.Save("table.pptx", SaveFormat.Pptx);
}

Смотрите также