本文整理汇总了C#中Section.AddTable方法的典型用法代码示例。如果您正苦于以下问题:C# Section.AddTable方法的具体用法?C# Section.AddTable怎么用?C# Section.AddTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Section
的用法示例。
在下文中一共展示了Section.AddTable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: addTable
private void addTable(Section section)
{
String[] header = { "Name", "Capital", "Continent", "Area", "Population" };
String[][] data =
{
new String[]{"Argentina", "Buenos Aires", "South America", "2777815", "32300003"},
new String[]{"Bolivia", "La Paz", "South America", "1098575", "7300000"},
new String[]{"Brazil", "Brasilia", "South America", "8511196", "150400000"},
new String[]{"Canada", "Ottawa", "North America", "9976147", "26500000"},
new String[]{"Chile", "Santiago", "South America", "756943", "13200000"},
new String[]{"Colombia", "Bagota", "South America", "1138907", "33000000"},
new String[]{"Cuba", "Havana", "North America", "114524", "10600000"},
new String[]{"Ecuador", "Quito", "South America", "455502", "10600000"},
new String[]{"El Salvador", "San Salvador", "North America", "20865", "5300000"},
new String[]{"Guyana", "Georgetown", "South America", "214969", "800000"},
new String[]{"Jamaica", "Kingston", "North America", "11424", "2500000"},
new String[]{"Mexico", "Mexico City", "North America", "1967180", "88600000"},
new String[]{"Nicaragua", "Managua", "North America", "139000", "3900000"},
new String[]{"Paraguay", "Asuncion", "South America", "406576", "4660000"},
new String[]{"Peru", "Lima", "South America", "1285215", "21600000"},
new String[]{"United States of America", "Washington", "North America", "9363130", "249200000"},
new String[]{"Uruguay", "Montevideo", "South America", "176140", "3002000"},
new String[]{"Venezuela", "Caracas", "South America", "912047", "19700000"}
};
Spire.Doc.Table table = section.AddTable();
table.ResetCells(data.Length + 1, header.Length);
// ***************** First Row *************************
TableRow row = table.Rows[0];
row.IsHeader = true;
row.Height = 20; //unit: point, 1point = 0.3528 mm
row.HeightType = TableRowHeightType.Exactly;
row.RowFormat.BackColor = Color.Gray;
for (int i = 0; i < header.Length; i++)
{
row.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
Paragraph p = row.Cells[i].AddParagraph();
p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
TextRange txtRange = p.AppendText(header[i]);
txtRange.CharacterFormat.Bold = true;
}
for (int r = 0; r < data.Length; r++)
{
TableRow dataRow = table.Rows[r + 1];
dataRow.Height = 20;
dataRow.HeightType = TableRowHeightType.Exactly;
dataRow.RowFormat.BackColor = Color.Empty;
for (int c = 0; c < data[r].Length; c++)
{
dataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
dataRow.Cells[c].AddParagraph().AppendText(data[r][c]);
}
}
}
示例2: AddForm
private void AddForm(Section section)
{
ParagraphStyle descriptionStyle = new ParagraphStyle(section.Document);
descriptionStyle.Name = "description";
descriptionStyle.CharacterFormat.FontSize = 12;
descriptionStyle.CharacterFormat.FontName = "Arial";
descriptionStyle.CharacterFormat.TextColor = Color.FromArgb(0x00, 0x45, 0x8e);
section.Document.Styles.Add(descriptionStyle);
Paragraph p1 = section.AddParagraph();
String text1
= "So that we can verify your identity and find your information, "
+ "please provide us with the following information. "
+ "This information will be used to create your online account. "
+ "Your information is not public, shared in anyway, or displayed on this site";
p1.AppendText(text1);
p1.ApplyStyle(descriptionStyle.Name);
Paragraph p2 = section.AddParagraph();
String text2
= "You must provide a real email address to which we will send your password.";
p2.AppendText(text2);
p2.ApplyStyle(descriptionStyle.Name);
p2.Format.AfterSpacing = 8;
//field group label style
ParagraphStyle formFieldGroupLabelStyle = new ParagraphStyle(section.Document);
formFieldGroupLabelStyle.Name = "formFieldGroupLabel";
formFieldGroupLabelStyle.ApplyBaseStyle("description");
formFieldGroupLabelStyle.CharacterFormat.Bold = true;
formFieldGroupLabelStyle.CharacterFormat.TextColor = Color.White;
section.Document.Styles.Add(formFieldGroupLabelStyle);
//field label style
ParagraphStyle formFieldLabelStyle = new ParagraphStyle(section.Document);
formFieldLabelStyle.Name = "formFieldLabel";
formFieldLabelStyle.ApplyBaseStyle("description");
formFieldLabelStyle.ParagraphFormat.HorizontalAlignment
= Spire.Doc.Documents.HorizontalAlignment.Right;
section.Document.Styles.Add(formFieldLabelStyle);
//add table
Table table = section.AddTable();
//2 columns of per row
table.DefaultColumnsNumber = 2;
//default height of row is 20point
table.DefaultRowHeight = 20;
//load form config data
using (Stream stream = File.OpenRead(@"..\..\..\..\..\..\Data\Form.xml"))
{
XPathDocument xpathDoc = new XPathDocument(stream);
XPathNodeIterator sectionNodes = xpathDoc.CreateNavigator().Select("/form/section");
foreach (XPathNavigator node in sectionNodes)
{
//create a row for field group label, does not copy format
TableRow row = table.AddRow(false);
row.Cells[0].CellFormat.BackColor = Color.FromArgb(0x00, 0x71, 0xb6);
row.Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
//label of field group
Paragraph cellParagraph = row.Cells[0].AddParagraph();
cellParagraph.AppendText(node.GetAttribute("name", ""));
cellParagraph.ApplyStyle(formFieldGroupLabelStyle.Name);
XPathNodeIterator fieldNodes = node.Select("field");
foreach (XPathNavigator fieldNode in fieldNodes)
{
//create a row for field, does not copy format
TableRow fieldRow = table.AddRow(false);
//field label
fieldRow.Cells[0].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
Paragraph labelParagraph = fieldRow.Cells[0].AddParagraph();
labelParagraph.AppendText(fieldNode.GetAttribute("label", ""));
labelParagraph.ApplyStyle(formFieldLabelStyle.Name);
fieldRow.Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
Paragraph fieldParagraph = fieldRow.Cells[1].AddParagraph();
String fieldId = fieldNode.GetAttribute("id", "");
switch (fieldNode.GetAttribute("type", ""))
{
case "text":
//add text input field
TextFormField field
= fieldParagraph.AppendField(fieldId, FieldType.FieldFormTextInput) as TextFormField;
//set default text
field.DefaultText = "";
field.Text = "";
break;
case "list":
//add dropdown field
DropDownFormField list
= fieldParagraph.AppendField(fieldId, FieldType.FieldFormDropDown) as DropDownFormField;
//add items into dropdown.
//.........这里部分代码省略.........