Aspose manipulating Excel and Word

Source: Internet
Author: User

This period of time has been doing Office report development Summary! The aspose operation encountered difficulties.

Read the picture in Excel save as a static diagram

        public void Readpic (string path, String topath) {Common com = new Common ();            int count = 1;                try {string filesavename = String.Empty; String Savepath = String.                Empty; int chartnum = sheet.                Charts.count;                Dictionary<int, aspose.cells.charts.chart> dic = new Dictionary<int, aspose.cells.charts.chart> ();                list<int> list = new list<int> (); for (int i = 0; i < Chartnum; i++) {Aspose.Cells.Charts.Chart Chart = sheet.                    Charts[i]; int Y = chart.                    Chartobject.y; List.                    ADD (Y); Dic.                ADD (Y, chart); } int[] Nums = list.                ToArray (); Com.                Insertsort (Nums);                          List = new list<int> (nums); for (int i = 0; i < list. Count; i++) {StRing name = com.                    GetFileName (count);                    Savepath = System.IO.Path.Combine (topath, name);                    Aspose.Cells.Charts.Chart Chart = dic[list[i]]; string NME = Chart.                    Name;                    Stream Imgestream = new FileStream (Savepath, FileMode.Create); Set the chart chart. CategoryAxis.TickLabels.Offset = 0;//x axis: The distance from the x-axis of the coordinate text chart. CategoryAxis.TickLabels.TextDirection = textdirectiontype.context;//Sets the direction of the text in the chart. Categoryaxis.hasmultilevellabels = true;//x Axis: Whether a multi-level label if (chart) is allowed. categoryaxis.ticklabels.rotationangle!=0) {chart.                    CategoryAxis.TickLabels.RotationAngle = 255; }//Chart. CategoryAxis.TickLabels.RotationAngle = 255;//x axis: Coordinate text alignment direction (set X-axis text alignment to center, set this to 0 chart.) Categoryaxis.minortickmark = tickmarktype.inside;//As an example of a pie chart: whether the picture text is displayed in a pie chart or outside a chart.Categoryaxis.ticklabelposition = Ticklabelpositiontype.nexttoaxis; Chart.                    Valueaxis.ticklabelposition = Ticklabelpositiontype.low; Chart.                    Legend.position = Legendpositiontype.bottom; Chart.                    Toimage (Imgestream, System.Drawing.Imaging.ImageFormat.Jpeg);//Save the picture stream to a format consistent file stream count + = 2;                Imgestream.close ();            }} catch (Exception ex) {throw; }        }

Note Using the Aspose operation to read a static picture is not entirely accurate in many cases the picture is not complete. It is mainly the text part of the picture. It's easy to use the Categoryaxis property, so it's not recommended to generate images with Aspose.


Read the displayed value of the cell's true display what's The row? Row class

Set the cell value model. Content = Row[j]. StringValue;


Read the value of the cell itself

ROW[J]. Value.tostring ()



Action Excel compare simple want what attribute style can leave a message to ask me


Then, you manipulate word

The first is to write a picture

  public void Writepic (string path)        {            if (path! = "" && System.IO.File.Exists (path))            {                Shape Shape = Builder. Insertimage (Path, Relativehorizontalposition.page,-1,              relativeverticalposition.paragraph,-1,-1,-1, Wraptype.inline);                Builder. ParagraphFormat.Alignment = paragraphalignment.center;//Horizontally aligns the                shape. RelativeHorizontalPosition = Relativehorizontalposition.page;                Shape. HorizontalAlignment = HorizontalAlignment.Center;                Shape. VerticalAlignment = Verticalalignment.center;            }        }
</pre><p> This code can insert a picture into a specified paragraph, the RelativeVerticalPosition enumeration is the appearance of various standard positioning to be successfully inserted into the specified paragraph must move the focus to the past. </p><p><pre name= "code" class= "CSharp" >builder. MoveTo (PAR);

Once you move the focus, you can insert the moved paragraph.


And then insert the table

  public void writetable (Wordcelllist model) {Aspose.Words.Tables.Table Table = Builder.            Starttable (); Populate the table contents: The initial bit of the small mark is different from the habit of the array, starting with 1, i.e. (2,2) means the 2nd row 2nd column for (int i = 0; i < model. RowNum; i++) {//Some lines are relatively short, regardless of it, other grids are automatically populated with empty int temp = model. Modellist[i].                Count; Builder.                Rowformat.heightrule = heightrule.exactly; Builder.                Rowformat.height = 20; Builder.                Rowformat.heightrule = heightrule.exactly; Paragraphalignment Paragraphalignmentvalue = Builder.                ParagraphFormat.Alignment; Builder.                ParagraphFormat.Alignment = Paragraphalignment.center; for (int j = 0; J < temp; J + +) {Wordcell data = model.                    MODELLIST[I][J]; Cell cell = Builder.                    InsertCell (); Builder. Cellformat.width = data.                    Width * 8; Builder. Cellformat.borders[bordertype.top]. LineStyle = Setborderstyle (d = Builder. CELLFORMAT.BORDERS[D]. LineStyle, Bordertype.top, data.                    Topborderstyle); Builder. Cellformat.borders[bordertype.left]. LineStyle = Setborderstyle (d = Builder. CELLFORMAT.BORDERS[D]. LineStyle, Bordertype.left, data.                    Leftborderstyle); Builder. Cellformat.borders[bordertype.right]. LineStyle = Setborderstyle (d = Builder. CELLFORMAT.BORDERS[D]. LineStyle, Bordertype.right, data.                    Rightborderstyle); Builder. Cellformat.borders[bordertype.bottom]. LineStyle = Setborderstyle (d = Builder. CELLFORMAT.BORDERS[D]. LineStyle, Bordertype.bottom, data.                    Bottomborderstyle); Builder. Cellformat.borders[bordertype.top]. Color = data.                    Topbordercolor; Builder. Cellformat.borders[bordertype.left]. Color = data.                    Leftbordercolor; Builder. Cellformat.borders[bordertype.right]. Color = data.                    Rightbordercolor; Builder. Cellformat.borders[bordertype.bottom]. Color = Data.                    Bottombordercolor; Builder.                    Cellformat.verticalmerge = Aspose.Words.Tables.CellMerge.None; Builder. cellformat.verticalalignment = cellverticalalignment.center;//Vertical Center alignment builder. CellFormat.Shading.BackgroundPatternColor = data.                    BackGround; #region font style mapping builder. Font.Color = data.                    Font.fontcolor; Builder. Font.Size = data.                    Font.fontheight; Builder. Font.Name = data.                    Font.fontname; Builder. Font.Bold = data.                    Font.fontbold; #endregion Builder. Write (data.                Content); } if (I! = model. RowNum) {Builder.                Endrow (); } table.                Alignment = Tablealignment.center; The table is automatically populated by width.            AutoFit (Autofitbehavior.autofittowindow); } builder.            Endtable ();        At this point the current paragraph is blank line removal can    Builder.        Currentparagraph.remove (); }
  Private LineStyle Setborderstyle (Func<bordertype, linestyle> Func, bordertype type, BorderStyle style)         {            LineStyle LineStyle = func (type);    &nbs P       switch (style)             {            &N Bsp   Case borderstyle.none:                    LineStyle = LINESTYLE.N one;                    break;                Case borderstyle.thin:                    LineStyle = line style.single;                    break;        &NBSP ;       Case borderstyle.medium:                    Linesty Le = Linestyle.single;                    break;            &NB Sp   Case borderstyle.dashed:                    break;    & nbsp           case borderstyle.dotted:                     LineStyle = linestyle.dot;                    break;                case borderstyle.thick:                    LineStyle = linestyle.thick;                    BREAK;&NBS P               case borderstyle.double:                    LineStyle = linestyle.double;                    BR eak;               case borderstyle.hair:              &N Bsp     LineStyle = linestyle.hairline;                    break;& nbsp               case borderstyle.mediumdashed:            & nbsp       LineStyle = linestyle.single;                    BR eak;                case borderstyle.dashdot:          &N Bsp         LineStyle = linestyle.dotdash;                  & nbsp break;                case borderstyle.mediumdashdot:        & nbsp           break;                Case Borderstyle.dashdotdot:                    break;        &NBSP ;       Case borderstyle.mediumdashdotdot:                  &NBS P break;                case borderstyle.slanteddashdot:                    break;                default:  &NB Sp                 LineStyle = linestyle.none;          &NBS P         break;           }            RET Urn linestyle;       }

Table. AutoFit the key to your table cell width is the base cell rendered.

One thing to note is that when the table is inserted, there will be more paragraphs to delete.

And then replace it.

Range. Replace ("&" + Str[i + 2], result, false, false);
Note You cannot replace \ r \ n

After a while, summarize the class library


Aspose manipulating Excel and Word

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.