Clone() public method

public Clone ( ) : Table,
return Table,
示例#1
0
        /// <summary>
        /// 传递多个Table
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async void SetTableDict(object sender, RoutedEventArgs e)
        {
            Dict dtl = new Dict();
            var  tbl = _tbl.Clone();

            tbl.AcceptChanges();
            dtl["table2"] = tbl;
            Dict result = await AtTest.SetTableDict(dtl);

            _tbInfo.Text = result.Count == 1 ? "调用成功!" : "调用不成功!";
        }
示例#2
0
        static void Main(string[] args)
        {
            string MyDir = @"E:\Aspose\Aspose Vs VSTO\Aspose.Words Features missing in VSTO 1.1\Sample Files\";

            // Load the document.
            Document doc = new Document(MyDir + "Splitting_Tables.doc");

            // Get the first table in the document.
            Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);

            // We will split the table at the third row (inclusive).
            Row row = firstTable.Rows[2];

            // Create a new container for the split table.
            Table table = (Table)firstTable.Clone(false);

            // Insert the container after the original.
            firstTable.ParentNode.InsertAfter(table, firstTable);

            // Add a buffer paragraph to ensure the tables stay apart.
            firstTable.ParentNode.InsertAfter(new Paragraph(doc), firstTable);

            Row currentRow;

            do
            {
                currentRow = firstTable.LastRow;
                table.PrependChild(currentRow);
            }while (currentRow != row);

            doc.Save(MyDir + "Splitting_Tables_Out.doc");
        }
示例#3
0
        /// <summary>
        /// 添加克隆表格
        /// </summary>
        protected void InsertCloneTable(int tableIndex)
        {
            if (doc == null)
            {
                return;
            }
            NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);

            if (tables == null || tables.Count == 0 || tableIndex >= tables.Count)
            {
                return;
            }
            Table table = tables[tableIndex] as Table;

            if (table == null)
            {
                return;
            }
            try
            {
                Table tableClone = (Table)table.Clone(true);
                table.ParentNode.InsertAfter(tableClone, table);
                table.ParentNode.InsertAfter(new Paragraph(doc), table);
                table  = null;
                tables = null;
            }
            catch (SystemException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
        }
示例#4
0
        public void InitDefinitions()
        {
            origTable = m_mainForm.Definition;

            var def = origTable?.Clone();

            if (def == null)
            {
                DialogResult result = MessageBox.Show(this, string.Format("Table {0} missing definition. Create default definition?", m_mainForm.DBCName),
                                                      "Definition Missing!",
                                                      MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Question,
                                                      MessageBoxDefaultButton.Button1);

                if (result != DialogResult.Yes)
                {
                    return;
                }

                def = CreateDefaultDefinition();
                if (def == null)
                {
                    MessageBox.Show(string.Format("Can't create default definitions for {0}", m_mainForm.DBCName));

                    def        = new Table();
                    def.Name   = m_mainForm.DBCName;
                    def.Fields = new List <Field>();
                }
            }

            InitForm(def);
        }
示例#5
0
        public void TestCopyMathTable()
        {
            var table = new Table();

            Assert.IsType <Table>(table);
            var atom  = LaTeXSettings.Placeholder;
            var atom2 = LaTeXSettings.Times;
            var atom3 = LaTeXSettings.Divide;
            var list  = new MathList {
                atom, atom2, atom3
            };
            var list2 = new MathList {
                atom3, atom2
            };

            table.SetCell(list, 0, 1);
            table.SetCell(list2, 0, 2);
            table.SetAlignment(ColumnAlignment.Left, 2);
            table.SetAlignment(ColumnAlignment.Right, 1);

            var clone = table.Clone(false);

            CheckClone(table, clone);
            Assert.Equal(clone.InterColumnSpacing, table.InterColumnSpacing);
            Assert.Equal(clone.Alignments, table.Alignments);
            Assert.False(ReferenceEquals(clone.Alignments, table.Alignments));
            Assert.False(ReferenceEquals(clone.Cells, table.Cells));
            Assert.False(ReferenceEquals(clone.Cells[0], table.Cells[0]));
            Assert.Equal(clone.Cells[0].Count, table.Cells[0].Count);
            Assert.Empty(clone.Cells[0][0]);
            CheckClone(table.Cells[0][1], clone.Cells[0][1]);
            CheckClone(table.Cells[0][2], clone.Cells[0][2]);
            Assert.False(ReferenceEquals(clone.Cells[0][0], table.Cells[0][0]));
        }
示例#6
0
        // Creates a clone of the state.
        public override Object Clone()
        {
            List <Hashtable> newApplicables = new List <Hashtable>();

            foreach (Hashtable applicable in applicables)
            {
                newApplicables.Add((Hashtable)applicable.Clone());
            }

            Operator newLastStep = new Operator();

            if (lastStep != null)
            {
                newLastStep = lastStep.Clone() as Operator;
            }

            Operator newNextStep = new Operator();

            if (nextStep != null)
            {
                newNextStep = nextStep.Clone() as Operator;
            }

            return(new Superposition((Hashtable)Table.Clone(), newLastStep, newNextStep, newApplicables, new HashSet <State>(States, States.Comparer)));
        }
示例#7
0
        static void Main(string[] args)
        {
            // Load the document.
            Document doc = new Document("../../data/document.doc");

            // Get the first table in the document.
            Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);

            // We will split the table at the third row (inclusive).
            Row row = firstTable.Rows[2];

            // Create a new container for the split table.
            Table table = (Table)firstTable.Clone(false);

            // Insert the container after the original.
            firstTable.ParentNode.InsertAfter(table, firstTable);

            // Add a buffer paragraph to ensure the tables stay apart.
            firstTable.ParentNode.InsertAfter(new Paragraph(doc), firstTable);

            Row currentRow;

            do
            {
                currentRow = firstTable.LastRow;
                table.PrependChild(currentRow);
            }while (currentRow != row);

            doc.Save("Table.SplitTable Out.doc");
        }
        /// <summary>
        /// Shows how to split a table into two tables in a specific row.
        /// </summary>
        private static void SplitTable(string dataDir, string fileName)
        {
            //ExStart:SplitTable
            // Load the document.
            Document doc = new Document(dataDir + fileName);

            // Get the first table in the document.
            Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);

            // We will split the table at the third row (inclusive).
            Row row = firstTable.Rows[2];

            // Create a new container for the split table.
            Table table = (Table)firstTable.Clone(false);

            // Insert the container after the original.
            firstTable.ParentNode.InsertAfter(table, firstTable);

            // Add a buffer paragraph to ensure the tables stay apart.
            firstTable.ParentNode.InsertAfter(new Paragraph(doc), firstTable);

            Row currentRow;

            do
            {
                currentRow = firstTable.LastRow;
                table.PrependChild(currentRow);
            }while (currentRow != row);

            dataDir = dataDir + "Table.SplitTable_out_.doc";
            // Save the finished document.
            doc.Save(dataDir);
            //ExEnd:SplitTable
            Console.WriteLine("\nTable splitted successfully into two tables.\nFile saved at " + dataDir);
        }
        public void SplitTable()
        {
            //ExStart:SplitTable
            Document doc = new Document(MyDir + "Tables.docx");

            Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);

            // We will split the table at the third row (inclusive).
            Row row = firstTable.Rows[2];

            // Create a new container for the split table.
            Table table = (Table)firstTable.Clone(false);

            // Insert the container after the original.
            firstTable.ParentNode.InsertAfter(table, firstTable);

            // Add a buffer paragraph to ensure the tables stay apart.
            firstTable.ParentNode.InsertAfter(new Paragraph(doc), firstTable);

            Row currentRow;

            do
            {
                currentRow = firstTable.LastRow;
                table.PrependChild(currentRow);
            } while (currentRow != row);

            doc.Save(ArtifactsDir + "WorkingWithTables.SplitTable.docx");
            //ExEnd:SplitTable
        }
        protected override void BuildSqlCommand()
        {
            var table = Table.Clone();

            table.Columns.Add("DataState", typeof(string));
            foreach (var r in Table.Rows.Cast <DataRow>())
            {
                var newRow = table.NewRow();
                if (r.RowState != DataRowState.Deleted)
                {
                    newRow.ItemArray    = r.ItemArray;
                    newRow["DataState"] = r.RowState.ToString();
                }
                else
                {
                    for (int i = 0; i < r.Table.Columns.Count; i++)
                    {
                        newRow[i] = r[i, DataRowVersion.Original];
                    }
                    newRow["DataState"] = r.RowState.ToString();
                }
                table.Rows.Add(newRow);
            }

            UpdateCommand = new SqlCommand
            {
                Connection     = new SqlConnection(@"Data Source=.\sql16; Initial Catalog = School; Integrated Security = true"),
                CommandText    = "BulkUpdatePerson",
                CommandType    = System.Data.CommandType.StoredProcedure,
                CommandTimeout = SqlTimeout
            };
            var tableParam = UpdateCommand.Parameters.AddWithValue("@inputData", table);

            tableParam.SqlDbType = System.Data.SqlDbType.Structured;
        }
示例#11
0
        static void Main(string[] args)
        {
            string filePath = @"..\..\..\..\Sample Files\";

            // Load a document that contains tables from the local file system.
            Document doc = new Document(filePath + "Tables.docx");

            // Get the first table in the document.
            Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);

            // We will split the table at the third row (inclusive).
            Row row = firstTable.Rows[2];

            // Create a new container for the split table.
            Table table = (Table)firstTable.Clone(false);

            // Insert the container after the original.
            firstTable.ParentNode.InsertAfter(table, firstTable);

            // Add a buffer paragraph to ensure the tables stay apart.
            firstTable.ParentNode.InsertAfter(new Paragraph(doc), firstTable);

            Row currentRow;

            do
            {
                currentRow = firstTable.LastRow;
                table.PrependChild(currentRow);
            }while (currentRow != row);

            doc.Save(filePath + "Tables Split.docx");
        }
        public List <BaseEntity> GetAllContainers(bool reset = false)
        {
            if (reset)
            {
                allContainers = null;
            }
            if (allContainers != null)
            {
                return(allContainers);
            }

            DynamicArea entity = Entity as DynamicArea;

            allContainers = new List <BaseEntity>();
            DataTable dt = this.Source != null ? this.Source.Table : null;

            if (dt == null)
            {
                return(allContainers);
            }
            for (int rowIndex = 0; rowIndex < dt.Rows.Count; rowIndex++)
            {
                for (int i = 0; i < entity.Tables.Length; i++)
                {
                    Table tmpTable = entity.Tables[i];
                    Table table    = (Table)tmpTable.Clone(tmpTable.ProductRule, tmpTable.Container);
                    //调整行位置(相对)
                    table.Location.RowIndex = entity.Location.RowCount * rowIndex + table.Location.RowIndex;
                    //获取数据源
                    table.SourceName = _dynamicObject.GetDynamicValue(table.SourceName, rowIndex);
                    //Source source = entity.GetDynamicSource(table.SourceName, rowIndex);
                    //if (source != null)
                    //{
                    //    table.Source = source;
                    //}
                    allContainers.Add(table);
                }

                for (int i = 0; i < entity.Cells.Length; i++)
                {
                    Cell tmpCell = entity.Cells[i];
                    Cell cell    = (Cell)tmpCell.Clone(tmpCell.ProductRule, tmpCell.Container);
                    //调整行位置(相对)
                    cell.Location.RowIndex = entity.Location.RowCount * rowIndex + cell.Location.RowIndex;
                    if (!string.IsNullOrEmpty(cell.SourceName))
                    {
                        //Source source = entity.GetDynamicSource(cell.SourceName, rowIndex);
                        //if (source != null) cell.Source = source;
                        cell.SourceName = _dynamicObject.GetDynamicValue(cell.SourceName, rowIndex);
                    }
                    if (!string.IsNullOrEmpty(cell.Value))
                    {
                        cell.Value = _dynamicObject.GetDynamicValue(cell.Value, rowIndex);
                    }
                    allContainers.Add(cell);
                }
            }
            return(allContainers);
        }
示例#13
0
文件: ResultSet.cs 项目: ywscr/NBi
 public ResultSet Clone()
 {
     var newRs = new ResultSet
     {
         Table = Table.Clone()
     };
     return newRs;
 }
        // ------------------------------------------
        // ACCESSORS
        // ------------------------------------------

        #region Accessors

        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>Returns the cloned instance.</returns>
        public override object Clone(params string[] areas)
        {
            var clone = base.Clone(areas) as DbJoinedTable;

            clone.Table     = Table?.Clone <DbTable>();
            clone.Condition = Condition?.Clone <DataExpression>();

            return(clone);
        }
示例#15
0
        public ICloneableElement Clone(Dictionary <ICloneableElement, ICloneableElement> objectTree, Predicate <ICloneableElement> doClone)
        {
            if (!doClone(this))
            {
                return(this);
            }

            Table.Clone(objectTree, doClone);
            return(objectTree[this]);
        }
示例#16
0
 private void StartBlinking(Table.TableElementData TableElementData)
 {
     if (!BlinkEnabled)
     {
         BlinkTableElementData = TableElementData.Clone();
         BlinkOrgTableElementDataValue = BlinkTableElementData.Value;
         BlinkEnabled = true;
         BlinkState = false;
         DoBlink();
     }
 }
示例#17
0
 public object Clone()
 {
     return(new GameBoard(TableSize, SlotsToWin)
     {
         Table = (int[, ])Table.Clone(),
         EmptySlots = new List <KeyValuePair <int, int> >(EmptySlots),
         Turn = Turn,
         Winner = Winner,
         SlotsToWin = SlotsToWin,
         TableSize = TableSize
     });
 }
示例#18
0
        private Image ConvertTableToImage(Table obj)
        {
            Document doc     = new Document();
            Section  section = doc.AddSection();

            section.Body.ChildObjects.Add(obj.Clone());

            Image image = doc.SaveToImages(0, ImageType.Bitmap);

            doc.Close();
            return(CutImageWhitePart(image as Bitmap, 1));
        }
示例#19
0
文件: RptMatrix.cs 项目: Daoting/dt
        /// <summary>
        /// 按排序条件重新整理数据
        /// </summary>
        /// <param name="p_data"></param>
        void ReBuildData(Table p_data)
        {
            string[] rowOrder = RowSort.ToLower().Split(',');
            string[] colOrder = ColSort.ToLower().Split(',');
            IOrderedEnumerable <Row> orderData = null;

            if (rowOrder.Length > 0)
            {
                orderData = Order(orderData, p_data.Clone(), rowOrder);
            }
            if (colOrder.Length > 0)
            {
                orderData = Order(orderData, p_data.Clone(), colOrder);
            }
            if (orderData != null)
            {
                p_data.Clear();
                foreach (Row dr in orderData)
                {
                    p_data.Add(dr);
                }
            }
        }
示例#20
0
 /// <summary>
 /// Triggers the DurationEffect with the given TableElementData.<br/>
 /// The duration is started, if the value portion of the TableElementData parameter is !=0. 
 /// Trigger calls with a TableElement value=0 have no effect.
 /// </summary>
 /// <param name="TableElementData">TableElementData for the TableElement which has triggered the effect.</param>
 public override void Trigger(Table.TableElementData TableElementData)
 {
     if (TargetEffect != null)
     {
         if (!Active || RetriggerBehaviour == RetriggerBehaviourEnum.RestartEffect)
         {
             if (TableElementData.Value != 0)
             {
                 TargetEffect.Trigger(TableElementData);
                 Table.Pinball.Alarms.RegisterAlarm(DurationMs, DurationEnd, TableElementData.Clone());
             }
             Active = true;
         }
     }
 }
示例#21
0
        public ICloneableElement Clone(Dictionary <ICloneableElement, ICloneableElement> objectTree, Predicate <ICloneableElement> doClone)
        {
            if (!doClone(this))
            {
                return(this);
            }

            if (!objectTree.TryGetValue(this, out var clone))
            {
                objectTree.Add(this, clone = new SqlJoinedTable(
                                   JoinType,
                                   (SqlTableSource)Table.Clone(objectTree, doClone),
                                   IsWeak,
                                   (SqlSearchCondition)Condition.Clone(objectTree, doClone)));
            }

            return(clone);
        }
示例#22
0
        public override ICloneableElement Clone(Dictionary <ICloneableElement, ICloneableElement> objectTree, Predicate <ICloneableElement> doClone)
        {
            if (!doClone(this))
            {
                return(this);
            }

            var clone = new SqlCreateTableStatement();

            if (Table != null)
            {
                clone.Table = (SqlTable)Table.Clone(objectTree, doClone);
            }

            objectTree.Add(this, clone);

            return(clone);
        }
示例#23
0
        /// <summary>
        /// 替换文件
        /// </summary>
        /// <param name="dt">要更新的数据</param>
        /// <param name="expPairColumn">当前要替换的数据字典</param>
        /// <returns></returns>
        private static bool GenerateTable(DataTable dt, Dictionary <string, string> expPairColumn, int index)
        {
            try
            {
                int tableNums = dt.Rows.Count;

                //获取所有表格
                NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);

                //获取第几个表格
                Table table      = allTables[index] as Table;
                Table tableClone = (Table)table.Clone(true);

                for (int i = 0; i < tableNums; i++)
                {
                    if (i == 0)
                    {
                        foreach (string key in expPairColumn.Keys)
                        {
                            var value  = dt.Rows[i][expPairColumn[key]].ToString();
                            var repStr = string.Format("{0}", key);
                            doc.Range.Replace(repStr, value.ToString(), false, false);
                        }
                        continue;
                    }

                    Table tableClone1 = (Table)tableClone.Clone(true);

                    table.ParentNode.InsertAfter(tableClone1, table);

                    foreach (string key in expPairColumn.Keys)
                    {
                        var value  = dt.Rows[i][expPairColumn[key]].ToString();
                        var repStr = string.Format("{0}", key);
                        doc.Range.Replace(repStr, value, false, false);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
示例#24
0
        public void SplitTable()
        {
            //ExStart
            //ExId:SplitTableAtRow
            //ExSummary:Shows how to split a table into two tables a specific row.
            // Load the document.
            Document doc = new Document(MyDir + "Table.SimpleTable.doc");

            // Get the first table in the document.
            Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);

            // We will split the table at the third row (inclusive).
            Row row = firstTable.Rows[2];

            // Create a new container for the split table.
            Table table = (Table)firstTable.Clone(false);

            // Insert the container after the original.
            firstTable.ParentNode.InsertAfter(table, firstTable);

            // Add a buffer paragraph to ensure the tables stay apart.
            firstTable.ParentNode.InsertAfter(new Paragraph(doc), firstTable);

            Row currentRow;

            do
            {
                currentRow = firstTable.LastRow;
                table.PrependChild(currentRow);
            } while (currentRow != row);

            doc.Save(MyDir + @"\Artifacts\Table.SplitTable.doc");
            //ExEnd

            doc = new Document(MyDir + @"\Artifacts\Table.SplitTable.doc");
            // Test we are adding the rows in the correct order and the
            // selected row was also moved.
            Assert.AreEqual(row, table.FirstRow);

            Assert.AreEqual(2, firstTable.Rows.Count);
            Assert.AreEqual(2, table.Rows.Count);
            Assert.AreEqual(2, doc.GetChildNodes(NodeType.Table, true).Count);
        }
        public void CloneCompleteTable()
        {
            //ExStart:CloneCompleteTable
            Document doc = new Document(MyDir + "Tables.docx");

            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Clone the table and insert it into the document after the original.
            Table tableClone = (Table)table.Clone(true);

            table.ParentNode.InsertAfter(tableClone, table);

            // Insert an empty paragraph between the two tables,
            // or else they will be combined into one upon saving this has to do with document validation.
            table.ParentNode.InsertAfter(new Paragraph(doc), table);

            doc.Save(ArtifactsDir + "WorkingWithTables.CloneCompleteTable.docx");
            //ExEnd:CloneCompleteTable
        }
示例#26
0
            /// <summary>
            /// Клонировать лист
            /// </summary>
            /// <returns>Копия листа</returns>
            public Worksheet Clone()
            {
                XmlNode   nodeClone      = node.CloneNode(false);
                Worksheet worksheetClone = new Worksheet(nodeClone);

                Table tableClone = table.Clone();

                worksheetClone.table = tableClone;
                nodeClone.AppendChild(tableClone.Node);

                foreach (XmlNode childNode in node.ChildNodes)
                {
                    if (childNode.Name != "Table")
                    {
                        nodeClone.AppendChild(childNode.Clone());
                    }
                }

                return(worksheetClone);
            }
示例#27
0
        static void Main(string[] args)
        {
            // Check for an Aspose.Words license file in the local file system and apply it, if it exists.
            string licenseFile = AppDomain.CurrentDomain.BaseDirectory + "Aspose.Words.lic";

            if (File.Exists(licenseFile))
            {
                Aspose.Words.License license = new Aspose.Words.License();

                // Use the license from the bin/debug/ Folder.
                license.SetLicense("Aspose.Words.lic");
            }

            // Load a document that contains tables.
            Document doc = new Document("../../data/document.doc");

            // Get the first table in the document.
            Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);

            // We will split the table at the third row (inclusive).
            Row row = firstTable.Rows[2];

            // Create a new container for the split table.
            Table table = (Table)firstTable.Clone(false);

            // Insert the container after the original.
            firstTable.ParentNode.InsertAfter(table, firstTable);

            // Add a buffer paragraph to ensure the tables stay apart.
            firstTable.ParentNode.InsertAfter(new Paragraph(doc), firstTable);

            Row currentRow;

            do
            {
                currentRow = firstTable.LastRow;
                table.PrependChild(currentRow);
            }while (currentRow != row);

            doc.Save("SplitTable.docx");
        }
示例#28
0
        public void CloneTable()
        {
            //ExStart
            //ExId:CloneTable
            //ExSummary:Shows how to make a clone of a table in the document and insert it after the original table.
            Document doc = new Document(MyDir + "Table.SimpleTable.doc");

            // Retrieve the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Create a clone of the table.
            Table tableClone = (Table)table.Clone(true);

            // Insert the cloned table into the document after the original
            table.ParentNode.InsertAfter(tableClone, table);

            // Insert an empty paragraph between the two tables or else they will be combined into one
            // upon save. This has to do with document validation.
            table.ParentNode.InsertAfter(new Paragraph(doc), table);

            doc.Save(MyDir + @"\Artifacts\Table.CloneTableAndInsert.doc");
            //ExEnd

            // Verify that the table was cloned and inserted properly.
            Assert.AreEqual(2, doc.GetChildNodes(NodeType.Table, true).Count);
            Assert.AreEqual(table.Range.Text, tableClone.Range.Text);

            //ExStart
            //ExId:CloneTableRemoveContent
            //ExSummary:Shows how to remove all content from the cells of a cloned table.
            foreach (Cell cell in tableClone.GetChildNodes(NodeType.Cell, true))
            {
                cell.RemoveAllChildren();
            }
            //ExEnd

            Assert.AreEqual(String.Empty, tableClone.ToString(SaveFormat.Text).Trim());
        }
示例#29
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Load the document
            string   input = @"..\..\..\..\..\..\Data\TableTemplate.docx";
            Document doc   = new Document();

            doc.LoadFromFile(input);

            //Get the first section
            Section se = doc.Sections[0];

            //Get the first table
            Table original_Table = (Table)se.Tables[0];

            //Copy the existing table to copied_Table via Table.clone()
            Table copied_Table = original_Table.Clone();

            string[] st = new string[] { "Spire.Presentation for .Net", "A professional " +
                                         "PowerPoint® compatible library that enables developers to create, read, " +
                                         "write, modify, convert and Print PowerPoint documents on any .NET framework, " +
                                         ".NET Core platform." };
            //Get the last row of table
            TableRow lastRow = copied_Table.Rows[copied_Table.Rows.Count - 1];

            //Change last row data
            for (int i = 0; i < lastRow.Cells.Count - 1; i++)
            {
                lastRow.Cells[i].Paragraphs[0].Text = st[i];
            }
            //Add copied_Table in section
            se.Tables.Add(copied_Table);

            //Save and launch document
            string output = "CloneTable.docx";

            doc.SaveToFile(output, FileFormat.Docx);
            Viewer(output);
        }
示例#30
0
        public virtual DataSet Clone()
        {
            // need to return the same type as this...
            DataSet Copy = (DataSet)Activator.CreateInstance(GetType(), true);

            CopyProperties(Copy);

            foreach (DataTable Table in Tables)
            {
                // tables are often added in no-args constructor, don't add them
                // twice.
                if (!Copy.Tables.Contains(Table.TableName))
                {
                    Copy.Tables.Add(Table.Clone());
                }
            }

            //Copy Relationships between tables after existance of tables
            //and setting properties correctly
            CopyRelations(Copy);

            return(Copy);
        }
示例#31
0
        /// <summary>
        /// Shows how to clone complete table.
        /// </summary>
        private static void CloneCompleteTable(string dataDir)
        {
            //ExStart:CloneCompleteTable
            Document doc = new Document(dataDir + "Table.SimpleTable.doc");

            // Retrieve the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            // Create a clone of the table.
            Table tableClone = (Table)table.Clone(true);

            // Insert the cloned table into the document after the original
            table.ParentNode.InsertAfter(tableClone, table);

            // Insert an empty paragraph between the two tables or else they will be combined into one
            // upon save. This has to do with document validation.
            table.ParentNode.InsertAfter(new Paragraph(doc), table);
            dataDir = dataDir + "Table.CloneTableAndInsert_out_.doc";

            // Save the document to disk.
            doc.Save(dataDir);
            //ExEnd:CloneCompleteTable
            Console.WriteLine("\nTable cloned successfully.\nFile saved at " + dataDir);
        }
示例#32
0
            private static int ExportToPdf(DataTable queryResults)
            {
                try
                {
                    PdfDocumentRenderer renderer = new PdfDocumentRenderer();
                    int fontSize = 10;
                    var pdfDoc   = new PdfDocument();
                    var pdfPage  = pdfDoc.AddPage();
                    var pdfGfx   = XGraphics.FromPdfPage(pdfPage);
                    ShadingHeader.Color       = Color.FromRgb(189, 212, 249);
                    ShadingAlternateRow.Color = Color.FromRgb(224, 236, 255);

                    // Create a new MigraDoc document
                    Document pdfDDocument = new Document();
                    pdfDDocument.Info.Title   = _title;
                    pdfDDocument.Info.Subject = _title + " PDF Generated by Data Lake Export (PDF) ";
                    pdfDDocument.Info.Author  = "Billy Willoughby";

                    SetupDefaultPage(ref pdfDDocument, ref fontSize);

                    //Setup Fonts
                    XFont myStandardFont = new XFont(FontFamily.GenericMonospace, fontSize, XFontStyle.Regular);
                    XFont myHeaderFont   = new XFont(FontFamily.GenericMonospace, fontSize, XFontStyle.Bold);
                    Font  fontStandard   = new Font(FontFamily.GenericMonospace.Name, fontSize);
                    Font  fontHeader     = new Font(FontFamily.GenericMonospace.Name, fontSize);
                    fontHeader.Bold = true;

                    CreateNewSection(ref pdfDDocument, _title);

                    string[] rowHeaders  = new string[queryResults.Columns.Count];
                    XSize[]  columnWidth = new XSize[queryResults.Columns.Count];


                    /*Holder for Column names*/
                    foreach (DataColumn thisColumn in queryResults.Columns)
                    {
                        rowHeaders[queryResults.Columns.IndexOf(thisColumn)] = thisColumn.ColumnName;
                        if (_rowBreak != "" && _rowBreak.ToUpper() == thisColumn.ColumnName.ToUpper() && _rowBreakLocation == null)
                        {
                            _rowBreakLocation = queryResults.Columns.IndexOf(thisColumn);
                        }
                    }

                    Table thisTable = CreateNewTable(ref pdfDDocument, ref rowHeaders, fontHeader, fontSize);

                    bool rowFlip = false;
                    //int documentRowIndex = 0;  //Row one was created in create table function
                    int tableRowIndex = 0;  //Row one was created in create table function

                    Row thisRow;
                    if (queryResults.Rows.Count > 0)
                    {
                        foreach (DataRow thisDataRow in queryResults.Rows)
                        {
                            if (queryResults.Rows.IndexOf(thisDataRow) / 5000.0 == Math.Truncate(queryResults.Rows.IndexOf(thisDataRow) / 5000.0))
                            {
                                Console.WriteLine("Reading Rows " + queryResults.Rows.IndexOf(thisDataRow) + "+");
                            }

                            if (queryResults.Rows.IndexOf(thisDataRow) == 1 && _rowBreak != "")
                            {
                                pdfDDocument.LastSection.AddParagraph(
                                    thisDataRow.ItemArray[(int)_rowBreakLocation].ToString().Trim());
                                pdfDDocument.LastSection.LastParagraph.AddBookmark(
                                    thisDataRow.ItemArray[(int)_rowBreakLocation].ToString().Trim());
                            }

                            if (_rowBreak != "" && _rowBreakLocation != null &&
                                thisDataRow.ItemArray[(int)_rowBreakLocation].ToString().Trim() != "" /*&& tableRowIndex > 1*/)
                            {
                                if (_rowBreak != "")
                                {
                                    _title = thisDataRow.ItemArray[(int)_rowBreakLocation].ToString().Trim();
                                    pdfDDocument.LastSection.PageSetup.TopMargin = Unit.FromInch(.65);
                                }

                                if (thisTable.Rows.Count > 1)
                                {
                                    Table finalTable = thisTable.Clone();
                                    AutosizeTableColumns(ref finalTable, ref rowHeaders, ref columnWidth, myStandardFont, myHeaderFont, fontSize);
                                    pdfDDocument.LastSection.Add(finalTable);
                                    CreateNewSection(ref pdfDDocument, thisDataRow.ItemArray[(int)_rowBreakLocation].ToString().Trim());
                                    thisTable     = CreateNewTable(ref pdfDDocument, ref rowHeaders, fontHeader, fontSize);
                                    columnWidth   = new XSize[queryResults.Columns.Count];
                                    tableRowIndex = 0;
                                }
                            }
                            tableRowIndex++;

                            thisRow             = thisTable.AddRow();
                            thisRow.Format.Font = fontStandard.Clone();
                            if (rowFlip)
                            {
                                rowFlip         = false;
                                thisRow.Shading = ShadingAlternateRow.Clone();
                            }
                            else
                            {
                                rowFlip = true;
                            }

                            foreach (DataColumn thisColumn in queryResults.Columns)
                            {
                                thisRow.Cells[queryResults.Columns.IndexOf(thisColumn)].AddParagraph(
                                    thisDataRow.ItemArray[queryResults.Columns.IndexOf(thisColumn)].ToString());

                                if (pdfGfx.MeasureString(thisDataRow.ItemArray[queryResults.Columns.IndexOf(thisColumn)].ToString(),
                                                         myStandardFont).Width > columnWidth[queryResults.Columns.IndexOf(thisColumn)].Width)
                                {
                                    columnWidth[queryResults.Columns.IndexOf(thisColumn)]       = pdfGfx.MeasureString(thisDataRow.ItemArray[queryResults.Columns.IndexOf(thisColumn)].ToString(), myStandardFont);
                                    columnWidth[queryResults.Columns.IndexOf(thisColumn)]       = pdfGfx.MeasureString(thisDataRow.ItemArray[queryResults.Columns.IndexOf(thisColumn)].ToString(), myStandardFont);
                                    columnWidth[queryResults.Columns.IndexOf(thisColumn)].Width = columnWidth[queryResults.Columns.IndexOf(thisColumn)].Width + fontSize;
                                }
                            }
                        }
                        //End Loop



                        AutosizeTableColumns(ref thisTable, ref rowHeaders, ref columnWidth, myStandardFont, myHeaderFont, fontSize);

                        pdfDDocument.LastSection.PageSetup.LeftMargin = Unit.FromInch(.25);

                        if (_rowBreak != "")
                        {
                            pdfDDocument.LastSection.PageSetup.TopMargin = Unit.FromInch(.75);
                        }
                        pdfDDocument.LastSection.Add(thisTable);
                    }
                    else
                    {
                        Console.WriteLine("No rows found.");
                        return(0);
                    }

                    Console.WriteLine("Rendering PDF ...");
                    if (_optionPdf == "4")
                    {
                        pdfDDocument.DefaultPageSetup.Orientation = Orientation.Landscape;
                        pdfDDocument.DefaultPageSetup.PageHeight  = Unit.FromInch(_intMajorWidth + .45 /*Margins*/);
                        pdfDDocument.DefaultPageSetup.PageWidth   = Unit.FromInch(11);
                    }

                    if (_optionPdf == "0")
                    {
                        if (_intMajorWidth + .45 /*Margins*/ <= 8) /*Letter*/
                        {
                            Console.WriteLine("Render Width: " + ((_intMajorWidth + .45).ToString("####.0")) + ", selecting Letter Portrait");
                            pdfDDocument.DefaultPageSetup.Orientation  = Orientation.Portrait;
                            pdfDDocument.DefaultPageSetup.PageHeight   = Unit.FromInch(11);
                            pdfDDocument.DefaultPageSetup.PageWidth    = Unit.FromInch(8.5);
                            pdfDDocument.DefaultPageSetup.RightMargin  = .25;
                            pdfDDocument.DefaultPageSetup.LeftMargin   = .25;
                            pdfDDocument.DefaultPageSetup.BottomMargin = .25;
                            pdfDDocument.DefaultPageSetup.TopMargin    = .25;
                        }

                        if (_intMajorWidth + .45 /*Margins*/ > 8 && _intMajorWidth + .45 /*Margins*/ <= 11) /*Letter Landscape*/
                        {
                            Console.WriteLine("Render Width: " + ((_intMajorWidth + .45).ToString("####.0")) + ", selecting Letter Landscape");
                            pdfDDocument.DefaultPageSetup.Orientation  = Orientation.Landscape;
                            pdfDDocument.DefaultPageSetup.PageHeight   = Unit.FromInch(11);
                            pdfDDocument.DefaultPageSetup.PageWidth    = Unit.FromInch(8.5);
                            pdfDDocument.DefaultPageSetup.RightMargin  = .25;
                            pdfDDocument.DefaultPageSetup.LeftMargin   = .25;
                            pdfDDocument.DefaultPageSetup.BottomMargin = .25;
                            pdfDDocument.DefaultPageSetup.TopMargin    = .25;
                        }

                        if (_intMajorWidth + .45 /*Margins*/ > 11 && _intMajorWidth + .45 /*Margins*/ <= 14) /*Legal Landscape*/
                        {
                            Console.WriteLine("Render Width: " + ((_intMajorWidth + .45).ToString("####.0")) + ", selecting Legal Landscape");
                            pdfDDocument.DefaultPageSetup.Orientation  = Orientation.Landscape;
                            pdfDDocument.DefaultPageSetup.PageHeight   = Unit.FromInch(14);
                            pdfDDocument.DefaultPageSetup.PageWidth    = Unit.FromInch(8.5);
                            pdfDDocument.DefaultPageSetup.RightMargin  = .25;
                            pdfDDocument.DefaultPageSetup.LeftMargin   = .25;
                            pdfDDocument.DefaultPageSetup.BottomMargin = .25;
                            pdfDDocument.DefaultPageSetup.TopMargin    = .25;
                        }

                        if (_intMajorWidth + .45 /*Margins*/ > 14) /*Custom*/
                        {
                            Console.WriteLine("Render Width: " + ((_intMajorWidth + .45).ToString("####.0")) + ", selecting Custom Paper");
                            pdfDDocument.DefaultPageSetup.PageHeight   = Unit.FromInch(_intMajorWidth + .45 /*Margins*/);
                            pdfDDocument.DefaultPageSetup.PageWidth    = Unit.FromInch(11);
                            pdfDDocument.DefaultPageSetup.Orientation  = Orientation.Landscape;
                            pdfDDocument.DefaultPageSetup.RightMargin  = .25;
                            pdfDDocument.DefaultPageSetup.LeftMargin   = .25;
                            pdfDDocument.DefaultPageSetup.BottomMargin = .25;
                            pdfDDocument.DefaultPageSetup.TopMargin    = .25;
                        }
                    }

                    Console.WriteLine("Rendering ...");


                    renderer.Document = pdfDDocument;
                    renderer.DocumentRenderer.PrepareDocumentProgress += DocumentRenderer_PrepareDocumentProgress;
                    renderer.DocumentRenderer.PrepareDocument();

                    renderer.RenderDocument();

                    // Save the document...
                    string filename = _filename;
                    Console.WriteLine();
                    Console.WriteLine("Writing to disk ...");
                    renderer.PdfDocument.Save(filename);
                    Console.WriteLine("Fini");
                    return(0);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(-4);
                }
            }