Exemplo n.º 1
0
 public void SetHeade(string strBookmarkName, string text)
 {
     if (_Doc.Range.Bookmarks[strBookmarkName] != null)
     {
         Aspose.Words.Bookmark mark = _Doc.Range.Bookmarks[strBookmarkName];
         mark.Text = text;
     }
 }
Exemplo n.º 2
0
 private void SetBookmark(ref Aspose.Words.Document doc, string title, string value)
 {
     Aspose.Words.Bookmark bookmark = doc.Range.Bookmarks[title];
     if (bookmark != null)
     {
         bookmark.Text = value;
     }
 }
Exemplo n.º 3
0
        public FileStreamResult ExportWordById(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(null);
            }

            InformationInfo info = BLLFactory <Information> .Instance.FindByID(id);

            if (info != null)
            {
                string template           = "~/Content/Template/政策法规模板.doc";
                string templateFile       = Server.MapPath(template);
                Aspose.Words.Document doc = new Aspose.Words.Document(templateFile);

                #region 使用文本方式替换
                //Dictionary<string, string> dictSource = new Dictionary<string, string>();
                //dictSource.Add("Title", info.Title);
                //dictSource.Add("Content", info.Content);
                //dictSource.Add("Editor", info.Editor);
                //dictSource.Add("EditTime", info.EditTime.ToString());
                //dictSource.Add("SubType", info.SubType);
                //foreach (string name in dictSource.Keys)
                //{
                //    doc.Range.Replace(name, dictSource[name], true, true);
                //}
                #endregion

                //使用书签方式替换
                SetBookmark(ref doc, "Title", info.Title);
                SetBookmark(ref doc, "Editor", info.Editor);
                SetBookmark(ref doc, "EditTime", info.EditTime.ToString());
                SetBookmark(ref doc, "SubType", info.SubType);

                //SetBookmark(ref doc, "Content", info.Content);
                //对于HTML内容,需要通过InsertHtml方式进行写入
                DocumentBuilder       builder  = new DocumentBuilder(doc);
                Aspose.Words.Bookmark bookmark = doc.Range.Bookmarks["Content"];
                if (bookmark != null)
                {
                    builder.MoveToBookmark(bookmark.Name);
                    builder.InsertHtml(info.Content);
                }

                doc.Save(System.Web.HttpContext.Current.Response, info.Title, Aspose.Words.ContentDisposition.Attachment,
                         Aspose.Words.Saving.SaveOptions.CreateSaveOptions(Aspose.Words.SaveFormat.Doc));

                HttpResponseBase response = ControllerContext.HttpContext.Response;
                response.Flush();
                response.End();
                return(new FileStreamResult(Response.OutputStream, "application/ms-word"));
            }
            return(null);
        }
Exemplo n.º 4
0
        public void InsertDocumentAtBookmark()
        {
            //ExStart
            //ExId:InsertDocumentAtBookmark
            //ExSummary:Invokes the InsertDocument method shown above to insert a document at a bookmark.
            Aspose.Words.Document mainDoc = new Aspose.Words.Document(MyDir + "InsertDocument1.doc");
            Aspose.Words.Document subDoc  = new Aspose.Words.Document(MyDir + "InsertDocument2.doc");

            Aspose.Words.Bookmark bookmark = mainDoc.Range.Bookmarks["insertionPlace"];
            InsertDocument(bookmark.BookmarkStart.ParentNode, subDoc);

            mainDoc.Save(MyDir + "InsertDocumentAtBookmark Out.doc");
            //ExEnd
        }
        public void AccessBookmarks()
        {
            //ExStart
            //ExFor:BookmarkCollection
            //ExFor:BookmarkCollection.Item(Int32)
            //ExFor:BookmarkCollection.Item(String)
            //ExSummary:Shows how to obtain bookmarks from a bookmark collection.
            Document doc = new Document(MyDir + "Bookmarks.doc");

            // By index.
            Bookmark bookmark1 = doc.Range.Bookmarks[0];

            // By name.
            Bookmark bookmark2 = doc.Range.Bookmarks["Bookmark2"];
            //ExEnd
        }
Exemplo n.º 6
0
        public void BookmarkRemove()
        {
            //ExStart
            //ExFor:Bookmark.Remove
            //ExSummary:Shows how to remove a particular bookmark from a document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Bookmark.doc");

            // Use the indexer of the Bookmarks collection to obtain the desired bookmark.
            Aspose.Words.Bookmark bookmark = doc.Range.Bookmarks["MyBookmark"];

            // Remove the bookmark. The bookmarked text is not deleted.
            bookmark.Remove();
            //ExEnd

            // Verify that the bookmarks were removed from the document.
            Assert.AreEqual(0, doc.Range.Bookmarks.Count);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Use an iterator and a visitor to print info of every bookmark in the collection.
        /// </summary>
        private static void PrintAllBookmarkInfo(BookmarkCollection bookmarks)
        {
            BookmarkInfoPrinter bookmarkVisitor = new BookmarkInfoPrinter();

            // Get each bookmark in the collection to accept a visitor that will print its contents.
            using (IEnumerator <Bookmark> enumerator = bookmarks.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Bookmark currentBookmark = enumerator.Current;

                    if (currentBookmark != null)
                    {
                        currentBookmark.BookmarkStart.Accept(bookmarkVisitor);
                        currentBookmark.BookmarkEnd.Accept(bookmarkVisitor);

                        Console.WriteLine(currentBookmark.BookmarkStart.GetText());
                    }
                }
            }
        }
Exemplo n.º 8
0
        public void BookmarkCollectionRemove()
        {
            //ExStart
            //ExFor:BookmarkCollection.Remove(Bookmark)
            //ExFor:BookmarkCollection.Remove(String)
            //ExFor:BookmarkCollection.RemoveAt
            //ExSummary:Demonstrates different methods of removing bookmarks from a document.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Bookmarks.doc");
            // Remove a particular bookmark from the document.
            Aspose.Words.Bookmark bookmark = doc.Range.Bookmarks[0];
            doc.Range.Bookmarks.Remove(bookmark);

            // Remove a bookmark by specified name.
            doc.Range.Bookmarks.Remove("Bookmark2");

            // Remove a bookmark at the specified index.
            doc.Range.Bookmarks.RemoveAt(0);
            //ExEnd

            Assert.AreEqual(0, doc.Range.Bookmarks.Count);
        }
Exemplo n.º 9
0
        public void TableColumnBookmarks()
        {
            //ExStart
            //ExFor:Bookmark.IsColumn
            //ExFor:Bookmark.FirstColumn
            //ExFor:Bookmark.LastColumn
            //ExSummary:Shows how to get information about table column bookmarks.
            Document doc = new Document(MyDir + "Table column bookmarks.doc");

            foreach (Bookmark bookmark in doc.Range.Bookmarks)
            {
                // If a bookmark encloses columns of a table, it is a table column bookmark, and its IsColumn flag set to true.
                Console.WriteLine($"Bookmark: {bookmark.Name}{(bookmark.IsColumn ? " (Column)" : "")}");
                if (bookmark.IsColumn)
                {
                    if (bookmark.BookmarkStart.GetAncestor(NodeType.Row) is Row row &&
                        bookmark.FirstColumn < row.Cells.Count)
                    {
                        // Print the contents of the first and last columns enclosed by the bookmark.
                        Console.WriteLine(row.Cells[bookmark.FirstColumn].GetText().TrimEnd(ControlChar.CellChar));
                        Console.WriteLine(row.Cells[bookmark.LastColumn].GetText().TrimEnd(ControlChar.CellChar));
                    }
                }
            }
            //ExEnd

            doc = DocumentHelper.SaveOpen(doc);

            Bookmark firstTableColumnBookmark  = doc.Range.Bookmarks["FirstTableColumnBookmark"];
            Bookmark secondTableColumnBookmark = doc.Range.Bookmarks["SecondTableColumnBookmark"];

            Assert.True(firstTableColumnBookmark.IsColumn);
            Assert.AreEqual(1, firstTableColumnBookmark.FirstColumn);
            Assert.AreEqual(3, firstTableColumnBookmark.LastColumn);

            Assert.True(secondTableColumnBookmark.IsColumn);
            Assert.AreEqual(0, secondTableColumnBookmark.FirstColumn);
            Assert.AreEqual(3, secondTableColumnBookmark.LastColumn);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Use an iterator and a visitor to print info of every bookmark from within a document.
        /// </summary>
        private static void PrintAllBookmarkInfo(Document doc)
        {
            // Create a DocumentVisitor
            BookmarkInfoPrinter bookmarkVisitor = new BookmarkInfoPrinter();

            // Get all bookmarks from the document
            BookmarkCollection bookmarks = doc.Range.Bookmarks;

            // Get the enumerator from the document's BookmarkCollection and iterate over the bookmarks
            IEnumerator enumerator = bookmarks.GetEnumerator();

            while (enumerator.MoveNext())
            {
                Bookmark currentBookmark = (Bookmark)enumerator.Current;

                // Accept our DocumentVisitor it to print information about our bookmarks
                currentBookmark.BookmarkStart.Accept(bookmarkVisitor);
                currentBookmark.BookmarkEnd.Accept(bookmarkVisitor);

                // Prints a blank line
                Console.WriteLine(currentBookmark.BookmarkStart.GetText());
            }
        }
Exemplo n.º 11
0
        public void TableColumnBookmarks()
        {
            //ExStart
            //ExFor:Bookmark.IsColumn
            //ExFor:Bookmark.FirstColumn
            //ExFor:Bookmark.LastColumn
            //ExSummary:Shows how to get information about table column bookmark.
            Document doc = new Document(MyDir + "Table column bookmarks.doc");

            foreach (Bookmark bookmark in doc.Range.Bookmarks)
            {
                Console.WriteLine("Bookmark: {0}{1}", bookmark.Name, bookmark.IsColumn ? " (Column)" : "");
                if (bookmark.IsColumn)
                {
                    if (bookmark.BookmarkStart.GetAncestor(NodeType.Row) is Row row &&
                        bookmark.FirstColumn < row.Cells.Count)
                    {
                        // Print text from the first and last cells containing in bookmark
                        Console.WriteLine(row.Cells[bookmark.FirstColumn].GetText().TrimEnd(ControlChar.CellChar));
                        Console.WriteLine(row.Cells[bookmark.LastColumn].GetText().TrimEnd(ControlChar.CellChar));
                    }
                }
            }
            //ExEnd

            Bookmark firstTableColumnBookmark  = doc.Range.Bookmarks["FirstTableColumnBookmark"];
            Bookmark secondTableColumnBookmark = doc.Range.Bookmarks["SecondTableColumnBookmark"];

            Assert.IsTrue(firstTableColumnBookmark.IsColumn);
            Assert.AreEqual(1, firstTableColumnBookmark.FirstColumn);
            Assert.AreEqual(3, firstTableColumnBookmark.LastColumn);

            Assert.IsTrue(secondTableColumnBookmark.IsColumn);
            Assert.AreEqual(0, secondTableColumnBookmark.FirstColumn);
            Assert.AreEqual(3, secondTableColumnBookmark.LastColumn);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Use an iterator and a visitor to print info of every bookmark from within a document.
        /// </summary>
        private static void PrintAllBookmarkInfo(BookmarkCollection bookmarks)
        {
            // Create a DocumentVisitor
            BookmarkInfoPrinter bookmarkVisitor = new BookmarkInfoPrinter();

            // Get the enumerator from the document's BookmarkCollection and iterate over the bookmarks
            using (IEnumerator <Bookmark> enumerator = bookmarks.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Bookmark currentBookmark = enumerator.Current;

                    // Accept our DocumentVisitor it to print information about our bookmarks
                    if (currentBookmark != null)
                    {
                        currentBookmark.BookmarkStart.Accept(bookmarkVisitor);
                        currentBookmark.BookmarkEnd.Accept(bookmarkVisitor);

                        // Prints a blank line
                        Console.WriteLine(currentBookmark.BookmarkStart.GetText());
                    }
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// 经济指标/报价取值
        /// </summary>
        public void ExpWD5(System.Data.DataTable dt5)
        {
            DataView dv10 = dt5.DefaultView;
            dv10.RowFilter = "TYPE='10'";
            DataTable dt10 = dv10.ToTable();

            DataView dv11 = dt5.DefaultView;
            dv11.RowFilter = "TYPE='11'";
            DataTable dt11 = dv11.ToTable();

            bookmark = doc.Range.Bookmarks["Z_A42_2"];
            if (bookmark != null)
            {
                bookmark.Text = dt11.Rows[1][2].ToString();
            }
            bookmark = doc.Range.Bookmarks["Z_A42_3"];
            if (bookmark != null)
            {
                bookmark.Text = dt11.Rows[1][3].ToString();
            }
            //--------------------------前言部分
            bookmark = doc.Range.Bookmarks["Z_A0_7"]; //污水处理设备
            if (bookmark != null)
            {
                bookmark.Text = dt11.Rows[1][2].ToString();
            }
            bookmark = doc.Range.Bookmarks["Z_A0_8"];//吨水占地面积
            if (bookmark != null)
            {
                bookmark.Text = dt11.Rows[1][3].ToString();
            }
            bookmark = doc.Range.Bookmarks["Z_A0_9"];//吨水运行费用平均
            if (bookmark != null)
            {
                bookmark.Text = (double.Parse(dt11.Rows[4][3].ToString()) +double.Parse(dt11.Rows[6][3].ToString())).ToString("0.00");
            }
            bookmark = doc.Range.Bookmarks["Z_A0_A1"];//吨水运行能耗
            if (bookmark != null)
            {
                bookmark.Text = dt11.Rows[2][3].ToString();
            }
            bookmark = doc.Range.Bookmarks["Z_A0_A2"];//吨水投资
            if (bookmark != null)
            {
                bookmark.Text = dt11.Rows[0][3].ToString();
            }
            bookmark = doc.Range.Bookmarks["Z_A0_A3"];//总投资
            if (bookmark != null)
            {
                bookmark.Text = dt11.Rows[0][2].ToString();
            }
        }
Exemplo n.º 14
0
        public void Remove()
        {
            //ExStart
            //ExFor:BookmarkCollection.Clear
            //ExFor:BookmarkCollection.Count
            //ExFor:BookmarkCollection.Remove(Bookmark)
            //ExFor:BookmarkCollection.Remove(String)
            //ExFor:BookmarkCollection.RemoveAt
            //ExFor:Bookmark.Remove
            //ExSummary:Shows how to remove bookmarks from a document.
            Document        doc     = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Insert five bookmarks with text inside their boundaries.
            for (int i = 1; i <= 5; i++)
            {
                string bookmarkName = "MyBookmark_" + i;

                builder.StartBookmark(bookmarkName);
                builder.Write($"Text inside {bookmarkName}.");
                builder.EndBookmark(bookmarkName);
                builder.InsertBreak(BreakType.ParagraphBreak);
            }

            // This collection stores bookmarks.
            BookmarkCollection bookmarks = doc.Range.Bookmarks;

            Assert.AreEqual(5, bookmarks.Count);

            // There are several ways of removing bookmarks.
            // 1 -  Calling the bookmark's Remove method:
            bookmarks["MyBookmark_1"].Remove();

            Assert.False(bookmarks.Any(b => b.Name == "MyBookmark_1"));

            // 2 -  Passing the bookmark to the collection's Remove method:
            Bookmark bookmark = doc.Range.Bookmarks[0];

            doc.Range.Bookmarks.Remove(bookmark);

            Assert.False(bookmarks.Any(b => b.Name == "MyBookmark_2"));

            // 3 -  Removing a bookmark from the collection by name:
            doc.Range.Bookmarks.Remove("MyBookmark_3");

            Assert.False(bookmarks.Any(b => b.Name == "MyBookmark_3"));

            // 4 -  Removing a bookmark at an index in the bookmark collection:
            doc.Range.Bookmarks.RemoveAt(0);

            Assert.False(bookmarks.Any(b => b.Name == "MyBookmark_4"));

            // We can clear the entire bookmark collection.
            bookmarks.Clear();

            // The text that was inside the bookmarks is still present in the document.
            Assert.That(bookmarks, Is.Empty);
            Assert.AreEqual("Text inside MyBookmark_1.\r" +
                            "Text inside MyBookmark_2.\r" +
                            "Text inside MyBookmark_3.\r" +
                            "Text inside MyBookmark_4.\r" +
                            "Text inside MyBookmark_5.", doc.GetText().Trim());
            //ExEnd
        }
Exemplo n.º 15
0
        public void ExpWD8(System.Data.DataTable dt8)
        {
            builder = new Aspose.Words.DocumentBuilder(doc);

            builder.MoveToBookmark("Z_A62_B_1");
            for (var i = 0; i < dt8.Rows.Count; i++)
            {
                for (var j = 0; j < dt8.Columns.Count - 1; j++)
                {
                    builder.InsertCell();
                    if (i == 0)
                    {
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Top.LineWidth = 2;

                    }
                    else if (i == dt8.Rows.Count - 1)
                    {
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Bottom.LineWidth = 2;
                    }
                    else
                    {
                        builder.CellFormat.Borders.LineWidth = 1;
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;

                    }
                    if (j == 0)
                    {
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;

                    }
                    else if (j == dt8.Columns.Count - 2)
                    {
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                    }
                    else
                    {
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                    }

                    //单元格合并

                    if ((i >= 4 &&i <= 5) && (j == 0||j==1))
                    {
                        if (i == 4) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 6 && i <= 7) && (j == 0 || j == 1))
                    {
                        if (i == 6) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 8 && i <= 13) && (j == 0 || j == 1))
                    {
                        if (i == 8) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else
                    {
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                    }

             //           builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                    builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
                    builder.CellFormat.Width = 100;
                    builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
                    builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐

                    if (j == 0) { builder.CellFormat.Width = 60; }
                    else if (j == 1) { builder.CellFormat.Width = 120; }
                    else if (j == 2) { builder.CellFormat.Width = 120; }
                    else if (j == 3) { builder.CellFormat.Width = 80; }
                    else if (j == 4) { builder.CellFormat.Width = 80; }
                    else if (j == 5) { builder.CellFormat.Width = 100; }
                    else if (j == 6) { builder.CellFormat.Width = 100; }
                    else if (j == 7) { builder.CellFormat.Width = 80; }
                    else if (j == 8) { builder.CellFormat.Width = 80; }
                    builder.Write(dt8.Rows[i][j].ToString());

                }

                builder.EndRow();

            }
            bookmark = doc.Range.Bookmarks["Z_A62_4"];
            bookmark.Text = dt8.Rows[6][3].ToString();
        }
Exemplo n.º 16
0
        public void ExpWD6(System.Data.DataTable dt6)
        {
            builder = new Aspose.Words.DocumentBuilder(doc);

            bookmark = doc.Range.Bookmarks["Z_A50_1"];
            if (bookmark != null)
            {
                bookmark.Text = dt6.Rows[20][6].ToString();
            }

            builder.MoveToBookmark("Z_A51_B_1");
            for (var i = 0; i < dt6.Rows.Count; i++)
            {
                for (var j = 0; j < dt6.Columns.Count - 1; j++)
                {
                    builder.InsertCell();
                    if (i == 0)
                    {
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Top.LineWidth = 2;

                    }
                    else if (i == dt6.Rows.Count - 1)
                    {
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                        builder.CellFormat.Borders.Bottom.LineWidth = 2;
                    }
                    else
                    {
                        builder.CellFormat.Borders.LineWidth = 1;
                        builder.CellFormat.Borders.Top.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;

                    }
                    if (j == 0)
                    {
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.None;

                    }
                    else if (j == dt6.Columns.Count - 2)
                    {
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.None;
                    }
                    else
                    {
                        builder.CellFormat.Borders.Left.LineStyle = LineStyle.Single;
                        builder.CellFormat.Borders.Right.LineStyle = LineStyle.Single;
                    }

                    //单元格合并
                    /*
                    if ((i >= 3 &&i <= 4) && j == 0)
                    {
                        if (i == 3) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 5 && i <=8) && j == 0)
                    {
                        if (i == 5) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 9 && i <= 11) && j == 0)
                    {
                        if (i == 9) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 12 && i <= 13) && j == 0)
                    {
                        if (i == 12) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else if ((i >= 18 && i <= 19) && j == 0)
                    {
                        if (i == 18) { builder.CellFormat.VerticalMerge = CellMerge.First; } else { builder.CellFormat.VerticalMerge = CellMerge.Previous; }
                    }
                    else
                    {
                        builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                    }
                    */

                    builder.CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.None;
                    builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
                    builder.CellFormat.Width = 100;
                    builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//垂直居中对齐
                    builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//水平居中对齐

                    if (j == 0) { builder.CellFormat.Width = 60; }
                    else if (j == 1) { builder.CellFormat.Width = 120; }
                    else if (j == 2) { builder.CellFormat.Width = 120; }
                    else if (j == 3) { builder.CellFormat.Width = 80; }
                    else if (j == 4) { builder.CellFormat.Width = 80; }
                    else if (j == 5) { builder.CellFormat.Width = 100; }
                    else if (j == 5) { builder.CellFormat.Width = 100; }
                    else if (j == 5) { builder.CellFormat.Width = 80; }
                    builder.Write(dt6.Rows[i][j].ToString());
                }

                builder.EndRow();
            }

            /*
            builder.MoveToBookmark("Z_A51_B_1");
            Aspose.Words.Tables.Table table = (Aspose.Words.Tables.Table)doc.GetChild(NodeType.Table, 0, true);
            int i = 0;
            if (dt6.Rows.Count > 0)
            {
                builder.InsertCell();
                builder.CellFormat.Borders.LineStyle = LineStyle.Single;
                builder.CellFormat.Borders.Color = System.Drawing.Color.Black;
                builder.CellFormat.VerticalMerge = CellMerge.None;
                builder.Write("Text in one cell");
                builder.EndRow();

                //设置单元格属性,合并单元格
                table.Rows[4].Cells[0].CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.First;
                for (int j = 0; j < dt6.Rows.Count - 1; j++)
                {
                    Aspose.Words.Tables.Row beforeRow = table.Rows[i++];
                    Aspose.Words.Tables.Row clonedRow = (Aspose.Words.Tables.Row)beforeRow.Clone(true);
                    table.InsertAfter(clonedRow, beforeRow);//插入到指定位置下面
                    DataRow dr = dt6.Rows[j];
                    //修改上行内容
                    builder.MoveToCell(0, i - 1, 1, 0);
                    builder.Write(dr[1].ToString());
                    //设置合并内容
               //     builder.MoveToCell(0, i, 0, 0);
                    builder.CellFormat.WrapText = true;
                    //合并单元格
                    clonedRow.Cells[0].CellFormat.VerticalMerge = Aspose.Words.Tables.CellMerge.Previous;
                }

                builder.MoveToCell(0, i, 1, 0);
                builder.Write(dt6.Rows[dt6.Rows.Count - 1][1].ToString());
            }
             * */
        }
Exemplo n.º 17
0
        /// <summary>
        /// 基本信息
        /// </summary>
        public void ExpWD1(System.Data.DataTable dt1)
        {
            #region 使用书签替换模式

            //赋值开始
            //方案名称
            bookmark = doc.Range.Bookmarks["Z_A0_1"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[0]["BS"].ToString();
            }
            //方案时间
            bookmark = doc.Range.Bookmarks["Z_A0_2"];
            if (bookmark != null)
            {
                bookmark.Text = dateToUpper(DateTime.Now);
            }
            //处理量
            bookmark = doc.Range.Bookmarks["Z_A0_3"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[3]["BS"].ToString();
            }
            //处理水源
            bookmark = doc.Range.Bookmarks["Z_A0_4"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[5]["BS"].ToString();
            }
            //出水水质1
            bookmark = doc.Range.Bookmarks["Z_A0_5"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[25]["BS"].ToString();
            }
            //出水水质2
            bookmark = doc.Range.Bookmarks["Z_A0_6"];
            if (bookmark != null)
            {
                if (dt1.Rows[26]["BS"].ToString() !=null)
                {
                bookmark.Text = "中\""+dt1.Rows[26]["BS"].ToString()+"\"";
                }
            }
            //设备占地
            bookmark = doc.Range.Bookmarks["Z_A0_7"];
            if (bookmark != null)
            {
                bookmark.Text = "[尚未取值]";
            }
            //吨水占地
            bookmark = doc.Range.Bookmarks["Z_A0_8"];
            if (bookmark != null)
            {
                bookmark.Text = "[尚未取值]";
            }
            //吨水运行费
            bookmark = doc.Range.Bookmarks["Z_A0_9"];
            if (bookmark != null)
            {
                bookmark.Text = "[尚未取值]";
            }
            //吨水运行能耗
            bookmark = doc.Range.Bookmarks["Z_A0_A1"];
            if (bookmark != null)
            {
                bookmark.Text = "[尚未取值]";
            }
            //吨水运行投资
            bookmark = doc.Range.Bookmarks["Z_A0_A2"];
            if (bookmark != null)
            {
                bookmark.Text = "[尚未取值]";
            }
            //总投资
            bookmark = doc.Range.Bookmarks["Z_A0_A3"];
            if (bookmark != null)
            {
                bookmark.Text = "[尚未取值]";
            }
            //----------------------------------------------------
            //项目名称
            bookmark = doc.Range.Bookmarks["Z_A11_1"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[0]["BS"].ToString();
            }
            //项目地点
            bookmark = doc.Range.Bookmarks["Z_A11_2"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[2]["BS"].ToString();
            }
            //处理量
            bookmark = doc.Range.Bookmarks["Z_A11_3"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[3]["BS"].ToString();
            }

            bookmark = doc.Range.Bookmarks["I_41_1"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[3]["BS"].ToString();
            }

            //结构
            bookmark = doc.Range.Bookmarks["Z_A11_4"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[19]["BS"].ToString();
            }
            //处理量
            bookmark = doc.Range.Bookmarks["Z_A13_1"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[3]["BS"].ToString();
            }
            //出水水质1
            bookmark = doc.Range.Bookmarks["Z_A14_1"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[25]["BS"].ToString();
            }
            //出水水质2
            bookmark = doc.Range.Bookmarks["Z_A14_2"];
            if (bookmark != null)
            {
                if (dt1.Rows[26]["BS"].ToString() != null)
                {
                    bookmark.Text = "中\"" + dt1.Rows[26]["BS"].ToString() + "\"";
                }
            }
            //出水COD
            bookmark = doc.Range.Bookmarks["Z_A14_B_21"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[6]["BS"].ToString();
            }
            //出水BOD5
            bookmark = doc.Range.Bookmarks["Z_A14_B_22"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[7]["BS"].ToString();
            }
            //出水SS
            bookmark = doc.Range.Bookmarks["Z_A14_B_23"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[8]["BS"].ToString();
            }
            //出水总氮
            bookmark = doc.Range.Bookmarks["Z_A14_B_24"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[9]["BS"].ToString();
            }
            //出水氨氮(NH3-N)
            bookmark = doc.Range.Bookmarks["Z_A14_B_25"];
            if (bookmark != null)
            {
                bookmark.Text = dt1.Rows[10]["BS"].ToString();
            }

            #endregion

            //doc.Save("testAdvice.doc", Aspose.Words.ContentDisposition.Attachment,Aspose.Words.Saving.SaveOptions.CreateSaveOptions(Aspose.Words.SaveFormat.Doc));
        }
Exemplo n.º 18
0
        /// <summary>
        /// 单位级数据传输
        /// </summary>
        public void ExpWD2(System.Data.DataTable dt2)
        {
            DataTable dtx = DataTableHelper.CreateTable("BH,SJCS,DW,SZ");
            dtx.Rows.Add(new object[] {  "设计参数", "单位", "数值"});
            dtx.Rows.Add(new object[] { "调节池池停留时间", "h", Convert.ToDouble(dt2.Rows[0][2].ToString()).ToString("0.00") });
            dtx.Rows.Add(new object[] { "调节池有效容积", "m³", Convert.ToDouble(dt2.Rows[1][2].ToString()).ToString("0.00") });
            if (Convert.ToDouble(dt2.Rows[2][2].ToString()).ToString("0.00") != "0.00")
            {
                dtx.Rows.Add(new object[] { "缺氧池停留时间", "h", Convert.ToDouble(dt2.Rows[2][2].ToString()).ToString("0.00") });
                dtx.Rows.Add(new object[] { "缺氧池有效容积", "m³", Convert.ToDouble(dt2.Rows[3][2].ToString()).ToString("0.00") });
            }

            dtx.Rows.Add(new object[] {  "好氧MBR池停留时间", "h", Convert.ToDouble(dt2.Rows[4][2].ToString()).ToString("0.00") });
            dtx.Rows.Add(new object[] { "好氧MBR池有效容积", "m³", Convert.ToDouble(dt2.Rows[5][2].ToString()).ToString("0.00") });
            dtx.Rows.Add(new object[] { "设备机房尺寸", "m", dt2.Rows[6][2].ToString() });
            SCTable(dtx, "Z_B_41");

            bookmark = doc.Range.Bookmarks["Z_A42_1"];//缺氧池停留时间
                if (bookmark != null)
                {
                    bookmark.Text = dt2.Rows[6][2].ToString();
                }

            if (Convert.ToDouble(dt2.Rows[2][2].ToString()).ToString("0.00") != "0.00")
            {
                bookmark = doc.Range.Bookmarks["Z_A22_1"];//缺氧池停留时间
                if (bookmark != null)
                {
                    //\r\n
                    bookmark.Text =
                      //  "有缺氧池的工艺\r\n" +
                        "调节池:均匀水质和水量,抵御水质、水量对处理设备造成的冲击负荷;\r\n" +
                        "缺氧池:在缺氧生物反应器中,将回流混合液中的硝酸盐反硝化为氮气,实现总氮脱除;" +
                        "好氧MBR池:通过微生物代谢活动,去除水中有机污染物;设置曝气管,除了供给微生物活动所需要的氧气,还对膜面进行冲刷,有效控制膜污染;通过回流和加药去除水中的氮和磷;\r\n" +
                        "平板膜组件:进行分离作用,去除悬浮颗粒物、病菌等有害微生物;\r\n" +
                        "化学清洗系统:当平板膜组件受到污染时对其进行在线化学清洗;\r\n" +
                        "除磷加药系统(如有):通过药剂的加入去除水中的磷;\r\n" +
                        "MSTD池:污泥同步浓缩消化池,通过曝气使池内的部分污泥好氧消化,实现减量化,同时经高效膜过滤降低污泥的含水率实现污泥快速浓缩。\r\n";
                }
            }
            else {
                bookmark = doc.Range.Bookmarks["Z_A22_1"];//缺氧池停留时间
                if (bookmark != null)
                {
                    bookmark.Text =
                       // "无缺氧池的工艺\r\n" +
                        "调节池:均匀水质和水量,抵御水质、水量对处理设备造成的冲击负荷;\r\n" +
                        "好氧MBR池:通过微生物代谢活动,去除水中有机污染物;设置曝气管,除供给微生物活动所需要的氧气,还对膜面进行冲刷,有效控制膜污染;\r\n" +
                        "平板膜组件:进行分离作用,去除悬浮颗粒物、病菌等有害微生物;\r\n" +
                        "化学清洗系统:当平板膜组件受到污染时对其进行在线化学清洗;\r\n" +
                        "除磷加药系统(如有):通过药剂的加入去除水中的磷;\r\n" +
                        "MSTD池:污泥同步浓缩消化池,通过曝气使池内的部分污泥好氧消化,实现减量化,同时经高效膜过滤降低污泥的含水率实现污泥快速浓缩加药。\r\n";
                }
            }
            string str = "";
            /*
            string str = "";
            bookmark = doc.Range.Bookmarks["Z_A41_B_13"]; //调节池池停留时间
            if (bookmark != null)
            {
                str = dt2.Rows[0][2].ToString();
                bookmark.Text = str;
            }
            bookmark = doc.Range.Bookmarks["Z_A41_B_23"]; //调节池有效容积
            if (bookmark != null)
            {
                str = dt2.Rows[1][2].ToString();
                bookmark.Text = Convert.ToDouble(str).ToString("0.00");
            }
            bookmark = doc.Range.Bookmarks["Z_A41_B_33"];//缺氧池停留时间
            if (bookmark != null)
            {
                str = dt2.Rows[2][2].ToString();
                bookmark.Text = Convert.ToDouble(str).ToString("0.00");
            }
            bookmark = doc.Range.Bookmarks["Z_A41_B_43"]; //缺氧池有效容积
            if (bookmark != null)
            {
                str = dt2.Rows[3][2].ToString();
                bookmark.Text = Convert.ToDouble(str).ToString("0.00");
            }
            bookmark = doc.Range.Bookmarks["Z_A41_B_53"];//好氧MBR池停留时间
            if (bookmark != null)
            {
                str = dt2.Rows[4][2].ToString();
                bookmark.Text = Convert.ToDouble(str).ToString("0.00");
            }
            bookmark = doc.Range.Bookmarks["Z_A41_B_63"];//好氧MBR池有效容积
            if (bookmark != null)
            {
                str = dt2.Rows[5][2].ToString();
                bookmark.Text = Convert.ToDouble(str).ToString("0.00");
            }
            */
            //Z_A41_B_73设备机房尺寸

            //-----------------------------------------
            bookmark = doc.Range.Bookmarks["Z_A62_1"];
            if (bookmark != null)
            {
                str = dt2.Select("BY1='D25' AND TYPE='JS'")[0][2].ToString();//回流比
                bookmark.Text = Convert.ToDouble(str).ToString("0.00");
            }
            bookmark = doc.Range.Bookmarks["Z_A62_2"];
            if (bookmark != null)
            {
                str = dt2.Select("BY1='D25' AND TYPE='JS'")[0][2].ToString();//回流比
                bookmark.Text = (Convert.ToDouble(str)*1.8).ToString("0.00");
            }
            bookmark = doc.Range.Bookmarks["Z_A62_3"];
            if (bookmark != null)
            {
                str = dt2.Select("BY1='D25' AND TYPE='JS'")[0][2].ToString();//回流比
                bookmark.Text = ((Convert.ToDouble(str) * 1.8) / (Convert.ToDouble(dt2.Select("BY1='D25' AND TYPE='JS'")[0][2].ToString()))).ToString("0.00");
            }

            bookmark = doc.Range.Bookmarks["Z_A42_B_13"];
            if (bookmark != null)
            {
                str = dt2.Select("BY1='D42' AND TYPE='JS'")[0][2].ToString();//回流比
                bookmark.Text = Convert.ToDouble(str).ToString("0.00");
            }
            bookmark = doc.Range.Bookmarks["Z_A42_B_23"];
            if (bookmark != null)
            {
                str = dt2.Select("BY1='D19' AND TYPE='JS'")[0][2].ToString();//回流比
                bookmark.Text = Convert.ToDouble(str).ToString("0.00");
            }
            bookmark = doc.Range.Bookmarks["Z_A42_B_33"];
            if (bookmark != null)
            {
                str = dt2.Select("BY1='D16' AND TYPE='JS'")[0][2].ToString();//回流比
                bookmark.Text = Convert.ToDouble(str).ToString("0.00");
            }
            bookmark = doc.Range.Bookmarks["Z_A42_B_43"];
            if (bookmark != null)
            {
                str = dt2.Select("BY1='D17' AND TYPE='JS'")[0][2].ToString();//回流比
                bookmark.Text = Convert.ToDouble(str).ToString("0.00");
            }
            bookmark = doc.Range.Bookmarks["Z_A42_B_53"];
            if (bookmark != null)
            {
                str = dt2.Select("BY1='I9' AND TYPE='JS'")[0][2].ToString();//替换I10
                bookmark.Text = Convert.ToDouble(str).ToString("0.00");
            }
            bookmark = doc.Range.Bookmarks["Z_A42_B_63"];
            if (bookmark != null)
            {
                str = dt2.Select("BY1='D25' AND TYPE='JS'")[0][2].ToString();//回流比
                bookmark.Text = Convert.ToDouble(str).ToString("0.00");
            }
            bookmark = doc.Range.Bookmarks["Z_A42_B_73"];
            if (bookmark != null)
            {
                str = dt2.Select("BY1='D34' AND TYPE='JS'")[0][2].ToString();//回流比
                bookmark.Text = Convert.ToDouble(str).ToString("0.00");
            }
            //Z_A42_B_13
        }