예제 #1
0
        // Exports a collection to a table in given Document. BookmarkName is the name of the bookmark associated
        // with the table.
        public static dynamic Export(string DocumentPath, string BookmarkName, int StartRow, bool BuildColumnHeadings, IVisualCollection collection, List <string> ColumnNames)
        {
            dynamic functionReturnValue   = null;
            List <ColumnMapping> mappings = new List <ColumnMapping>();
            ColumnMapping        map      = default(ColumnMapping);
            dynamic         doc           = null;
            WordHelper      wordProxy     = new WordHelper();
            FieldDefinition fd            = default(FieldDefinition);

            // 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)
            {
                fd  = collection.GetFieldDefinition(name);
                map = new ColumnMapping("", name);
                if (fd == null)
                {
                    map.TableField.DisplayName = name;
                }
                else
                {
                    map.TableField = fd;
                }
                mappings.Add(map);
            }

            functionReturnValue = Export(doc, BookmarkName, StartRow, BuildColumnHeadings, collection, mappings);
            wordProxy.ShowDocument();
            return(functionReturnValue);
        }
예제 #2
0
        // Exports a collection to a table in given Document. BookmarkName is the name of the bookmark associated
        // with the table.
        public static dynamic Export(dynamic Document, string BookmarkName, int StartRow, bool BuildColumnHeadings, IVisualCollection collection, List <string> ColumnNames)
        {
            List <ColumnMapping> mappings = new List <ColumnMapping>();
            ColumnMapping        map      = default(ColumnMapping);
            FieldDefinition      fd       = default(FieldDefinition);

            foreach (string name in ColumnNames)
            {
                fd  = collection.GetFieldDefinition(name);
                map = new ColumnMapping("", name);
                if (fd == null)
                {
                    map.TableField.DisplayName = name;
                }
                else
                {
                    map.TableField = fd;
                }
                mappings.Add(map);
            }

            return(Export(Document, BookmarkName, StartRow, BuildColumnHeadings, collection, mappings));
        }
예제 #3
0
        // Imports a range starting at the location specified by workbook, worksheet, and range.
        // Workbook should be the full path to the workbook.
        public static void Import(IVisualCollection collection, string Workbook, string Worksheet, string Range, List <ColumnMapping> ColumnMapping)
        {
            _collection     = collection;
            _columnMappings = ColumnMapping;

            // Ensure that we have the correct and complete field definition.
            foreach (OfficeSharp.ColumnMapping map in _columnMappings)
            {
                map.TableField = collection.GetFieldDefinition(map.TableField.Name);
            }

            Dispatchers.Main.BeginInvoke(() =>
            {
                ExcelHelper xlProxy = new ExcelHelper();
                dynamic wb          = null;
                dynamic ws          = null;
                dynamic rg          = null;

                wb = xlProxy.Excel.Workbooks.Open(Workbook);
                if ((wb != null))
                {
                    ws = wb.Worksheets(Worksheet);
                    if ((ws != null))
                    {
                        rg             = ws.Range(Range);
                        _excelDocRange = ConvertToArray(rg);
                        ValidateData();
                    }
                }

                rg = null;
                ws = null;
                wb.Close(false);
                wb = null;
                xlProxy.Dispose();
            });
        }
예제 #4
0
        // Exports a collection to a table in given Document. BookmarkName is the name of the bookmark associated
        // with the table.
        public static dynamic Export(dynamic Document, string BookmarkName, int StartRow, bool BuildColumnHeadings, IVisualCollection collection, List<string> ColumnNames)
        {
            List<ColumnMapping> mappings = new List<ColumnMapping>();
            ColumnMapping map = default(ColumnMapping);
            FieldDefinition fd = default(FieldDefinition);

            foreach (string name in ColumnNames)
            {
                fd = collection.GetFieldDefinition(name);
                map = new ColumnMapping("", name);
                if (fd == null)
                {
                    map.TableField.DisplayName = name;
                }
                else
                {
                    map.TableField = fd;
                }
                mappings.Add(map);
            }

            return Export(Document, BookmarkName, StartRow, BuildColumnHeadings, collection, mappings);
        }
예제 #5
0
        // Exports a collection to a table in given Document. BookmarkName is the name of the bookmark associated
        // with the table.
        public static dynamic Export(string DocumentPath, string BookmarkName, int StartRow, bool BuildColumnHeadings, IVisualCollection collection, List<string> ColumnNames)
        {
            dynamic functionReturnValue = null;
            List<ColumnMapping> mappings = new List<ColumnMapping>();
            ColumnMapping map = default(ColumnMapping);
            dynamic doc = null;
            WordHelper wordProxy = new WordHelper();
            FieldDefinition fd = default(FieldDefinition);

            // 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)
            {
                fd = collection.GetFieldDefinition(name);
                map = new ColumnMapping("", name);
                if (fd == null)
                {
                    map.TableField.DisplayName = name;
                }
                else
                {
                    map.TableField = fd;
                }
                mappings.Add(map);
            }

            functionReturnValue = Export(doc, BookmarkName, StartRow, BuildColumnHeadings, collection, mappings);
            wordProxy.ShowDocument();
            return functionReturnValue;
        }