// Exports an IEntityCollection to a table in given Document. BookmarkName is the name of the bookmark associated // with the table. public static dynamic ExportEntityCollection(string DocumentPath, string BookmarkName, int StartRow, bool BuildColumnHeadings, IEntityCollection collection, List <string> ColumnNames) { dynamic functionReturnValue = null; List <ColumnMapping> mappings = new List <ColumnMapping>(); ColumnMapping map = default(ColumnMapping); dynamic doc = null; WordHelper wordProxy = new WordHelper(); // if Word is active then use it if (!wordProxy.GetWord()) { if (!wordProxy.CreateWord()) { throw new System.Exception("Could not start Microsoft Word."); } } wordProxy.OpenDocument(DocumentPath); doc = wordProxy.Document; foreach (string name in ColumnNames) { map = new ColumnMapping("", name); map.TableField.DisplayName = name; mappings.Add(map); } functionReturnValue = ExportEntityCollection(doc, BookmarkName, StartRow, BuildColumnHeadings, collection, mappings); wordProxy.ShowDocument(); return(functionReturnValue); }
public static dynamic GenerateDocument(string Template, IEntityObject Item, List <ColumnMapping> ColumnMappings) { dynamic doc = null; WordHelper wordProxy = new WordHelper(); wordProxy.CreateWord(); wordProxy.OpenDocument(Template); PopulateContentControls(ColumnMappings, Item, wordProxy); doc = wordProxy.Document; wordProxy.ShowDocument(); return(doc); }
// Exports an IEntityCollection to a table in given Document. BookmarkName is the name of the bookmark associated // with the table. public static dynamic ExportEntityCollection(string DocumentPath, string BookmarkName, int StartRow, bool BuildColumnHeadings, IEntityCollection collection, List <ColumnMapping> ColumnNames) { dynamic functionReturnValue = null; dynamic doc = null; WordHelper wordProxy = new WordHelper(); // if Word is active then use it if (!wordProxy.GetWord()) { if (!wordProxy.CreateWord()) { throw new System.Exception("Could not start Microsoft Word."); } } wordProxy.OpenDocument(DocumentPath); doc = wordProxy.Document; functionReturnValue = ExportEntityCollection(doc, BookmarkName, StartRow, BuildColumnHeadings, collection, ColumnNames); wordProxy.ShowDocument(); return(functionReturnValue); }
public static dynamic GenerateDocument(string Template, IEntityObject Item, List<ColumnMapping> ColumnMappings) { dynamic doc = null; WordHelper wordProxy = new WordHelper(); wordProxy.CreateWord(); wordProxy.OpenDocument(Template); PopulateContentControls(ColumnMappings, Item, wordProxy); doc = wordProxy.Document; wordProxy.ShowDocument(); return doc; }
// Exports an IEntityCollection to a table in given Document. BookmarkName is the name of the bookmark associated // with the table. public static dynamic ExportEntityCollection(string DocumentPath, string BookmarkName, int StartRow, bool BuildColumnHeadings, IEntityCollection collection, List<ColumnMapping> ColumnNames) { dynamic functionReturnValue = null; dynamic doc = null; WordHelper wordProxy = new WordHelper(); // if Word is active then use it if (!wordProxy.GetWord()) { if (!wordProxy.CreateWord()) { throw new System.Exception("Could not start Microsoft Word."); } } wordProxy.OpenDocument(DocumentPath); doc = wordProxy.Document; functionReturnValue = ExportEntityCollection(doc, BookmarkName, StartRow, BuildColumnHeadings, collection, ColumnNames); wordProxy.ShowDocument(); return functionReturnValue; }
// Exports an IEntityCollection to a table in given Document. BookmarkName is the name of the bookmark associated // with the table. public static dynamic ExportEntityCollection(string DocumentPath, string BookmarkName, int StartRow, bool BuildColumnHeadings, IEntityCollection collection, List<string> ColumnNames) { dynamic functionReturnValue = null; List<ColumnMapping> mappings = new List<ColumnMapping>(); ColumnMapping map = default(ColumnMapping); dynamic doc = null; WordHelper wordProxy = new WordHelper(); // if Word is active then use it if (!wordProxy.GetWord()) { if (!wordProxy.CreateWord()) { throw new System.Exception("Could not start Microsoft Word."); } } wordProxy.OpenDocument(DocumentPath); doc = wordProxy.Document; foreach (string name in ColumnNames) { map = new ColumnMapping("", name); map.TableField.DisplayName = name; mappings.Add(map); } functionReturnValue = ExportEntityCollection(doc, BookmarkName, StartRow, BuildColumnHeadings, collection, mappings); wordProxy.ShowDocument(); return functionReturnValue; }
// Exports an IEntityCollection to a table in either the active (UseActiveDocument = True) or a new document (UseActiveDocument = False) public static dynamic ExportEntityCollection(IEntityCollection collection, bool UseActiveDocument) { dynamic doc = null; WordHelper wordProxy = new WordHelper(); bool bUseActiveDocument = false; dynamic rg = null; // if Word is active then use it if (wordProxy.GetWord()) { // obtain a reference to the selection range if (UseActiveDocument) { rg = wordProxy.Word.Selection.Range; bUseActiveDocument = true; } else { wordProxy.CreateDocument(); } } else { wordProxy.CreateWord(); wordProxy.CreateDocument(); } List<string> columnNames = new List<string>(); // get column properties IEnumerable<IEntityProperty> columnProperties = collection.OfType<IEntityObject>().First().Details.Properties.All(); int columnCounter = 1; int rowCounter = 1; // add table dynamic oTable = null; if (bUseActiveDocument) { oTable = wordProxy.AddTable(1, columnProperties.Count(), rg); } else { oTable = wordProxy.AddTable(1, columnProperties.Count()); } // add columns names to the list foreach (IEntityProperty entityProperty in columnProperties) { columnNames.Add(entityProperty.Name); // add column headers to table wordProxy.SetTableCell(oTable, 1, columnCounter, entityProperty.DisplayName); columnCounter += 1; } // add values on the row following the headers rowCounter = 2; // iterate the collection and extract values by column name foreach (IEntityObject entityObj in collection) { oTable.Rows.Add(); for (int i = 0; i <= columnNames.Count - 1; i++) { wordProxy.SetTableCell(oTable, rowCounter, i + 1, LightSwitchHelper.GetValue(entityObj, columnNames[i])); } rowCounter += 1; } doc = wordProxy.Document; wordProxy.ShowDocument(); return doc; }
// Exports an IVisualCollection to a table in either the active (UseActiveDocument = True) or a new document (UseActiveDocument = False) public static dynamic Export(IVisualCollection collection, bool UseActiveDocument) { dynamic doc = null; WordHelper wordProxy = new WordHelper(); bool bUseActiveDocument = false; dynamic rg = null; // if Word is active then use it if (wordProxy.GetWord()) { // obtain a reference to the selection range if (UseActiveDocument) { rg = wordProxy.Word.Selection.Range; bUseActiveDocument = true; } else { wordProxy.CreateDocument(); } } else { wordProxy.CreateWord(); wordProxy.CreateDocument(); } List <string> columnNames = new List <string>(); if (collection.Count > 0) { // get column properties IEnumerable <IEntityProperty> columnProperties = collection.OfType <IEntityObject>().First().Details.Properties.All(); int columnCounter = 1; int rowCounter = 1; // add table dynamic oTable = null; if (bUseActiveDocument) { oTable = wordProxy.AddTable(collection.Count + 1, columnProperties.Count(), rg); } else { oTable = wordProxy.AddTable(collection.Count + 1, columnProperties.Count()); } // add columns names to the list foreach (IEntityProperty entityProperty in columnProperties) { columnNames.Add(entityProperty.Name); // add column headers to table wordProxy.SetTableCell(oTable, 1, columnCounter, entityProperty.DisplayName); columnCounter += 1; } // add values on the row following the headers rowCounter = 2; // iterate the collection and extract values by column name foreach (IEntityObject entityObj in collection) { for (int i = 0; i <= columnNames.Count - 1; i++) { wordProxy.SetTableCell(oTable, rowCounter, i + 1, LightSwitchHelper.GetValue(entityObj, columnNames[i])); } rowCounter += 1; } } doc = wordProxy.Document; wordProxy.ShowDocument(); return(doc); }