Rev 2104 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
using System;using Word;namespace EA_DocGen{/// <summary>/// Summary description for TabularContent./// </summary>public class TabularContent{private Word.Application WordApp = null;private Word.Document WordDocument = null;private Word.Range WordRange;private object startLocation;private object endLocation;public TabularContent(Word.Application wordApp, Word.Document wordDocument){WordApp = wordApp;WordDocument = wordDocument;//// TODO: Add constructor logic here//}public void AcceptWordAppAndDoc(Word.Application wordApp, Word.Document wordDocument){WordApp = wordApp;WordDocument = wordDocument;}public int Table_Create(string tableTitle, int numRows, int numCols){WordDocument.Content.InsertParagraphAfter();SelectInsertionPointAtEndOfDocument();Table_InsertCaption(tableTitle);startLocation = WordDocument.Content.End;WordDocument.Content.InsertParagraphAfter();endLocation = WordDocument.Content.End;WordRange = WordDocument.Range(ref startLocation, ref endLocation);object defaultTableBehaviour = Type.Missing;object autofitBehaviour = Type.Missing;Word.Table Table = WordDocument.Tables.Add( WordRange, numRows, numCols, ref defaultTableBehaviour, ref autofitBehaviour );Table.Rows[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray20;Table.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;Table.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;Table.Select();object tableTextStyle = EA_Constants.styleName_TableText;Table.Range.set_Style( ref tableTextStyle );return WordDocument.Tables.Count;}public int Table_CreateInvisible(int numRows, int numCols){WordDocument.Content.InsertParagraphAfter();SelectInsertionPointAtEndOfDocument();startLocation = WordDocument.Content.End;WordDocument.Content.InsertParagraphAfter();endLocation = WordDocument.Content.End;WordRange = WordDocument.Range(ref startLocation, ref endLocation);object defaultTableBehaviour = Type.Missing;object autofitBehaviour = Type.Missing;Word.Table Table = WordDocument.Tables.Add( WordRange, numRows, numCols, ref defaultTableBehaviour, ref autofitBehaviour );Table.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleNone;Table.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleNone;Table.Select();object tableTextStyle = EA_Constants.styleName_TableText;Table.Range.set_Style( ref tableTextStyle );return WordDocument.Tables.Count;}public void Table_SetTableColumnTitle(Word.Table table, string title, int column){table.Rows[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray10;table.Cell(1,column).Range.Text = title;table.Cell(1,column).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;table.Cell(1,column).Range.Font.Bold = 1;}public void Table_SetTableCellTitle(Word.Table table, string title, int row, int column){table.Cell(row,column).Shading.BackgroundPatternColor = Word.WdColor.wdColorGray20;table.Cell(row,column).Range.Text = title;table.Cell(row,column).Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;table.Cell(row,column).Range.Font.Bold = 1;}public int Table_InsertNewRowAfterThisRow(Word.Table table, int row){table.Rows[row].Select();object rowC = 1;WordApp.Selection.InsertRowsBelow(ref rowC);table.Rows[row+1].Shading.BackgroundPatternColor = Word.WdColor.wdColorWhite;return row+1;}public int Table_AppendSeperatorAndNewRowAfterThisRow(Word.Table table, int row){// add two more rows, the first being a seperatorint seperatorRow = Table_InsertNewRowAfterThisRow(table, row);int newRow = Table_InsertNewRowAfterThisRow(table, seperatorRow);// Make seperator row, one cell wide, and remove its left & right borderstable.Rows[seperatorRow].Select();WordApp.Selection.Cells.Merge();WordApp.Selection.Borders[Word.WdBorderType.wdBorderLeft].LineStyle = Word.WdLineStyle.wdLineStyleNone;WordApp.Selection.Borders[Word.WdBorderType.wdBorderRight].LineStyle = Word.WdLineStyle.wdLineStyleNone;return newRow;}public void Table_MergeCellsInThisRow(Word.Table table, int row){table.Rows[row].Select();WordApp.Selection.Cells.Merge();}public void Table_InsertCaption(string captionText){object Label = "Table";object Title = Type.Missing;object TitleAutoText = Type.Missing;object Position = Word.WdCaptionPosition.wdCaptionPositionAbove;object ExcludeLabel = 0;WordApp.Selection.InsertCaption( ref Label, ref Title, ref TitleAutoText, ref Position, ref ExcludeLabel);WordApp.Selection.TypeText( ": " + captionText);WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;}private void SelectInsertionPointAtEndOfDocument(){object unit;object extend;unit = Word.WdUnits.wdStory;extend = Word.WdMovementType.wdMove;WordApp.Selection.EndKey(ref unit, ref extend);}}}