Aspose.Cells.dll Reference Import Export Excel

Source: Internet
Author: User
Tags httpcontext

Aspose.cells Import and Export Excel

Article Source: http://hi.baidu.com/leilongbing/item/c11467e1819e5417595dd8c1

Modify Style
Workbook Workbook = new Workbook (); Workbooks

Worksheet sheet = workbook. Worksheets[0]; Work table

Cells cells = sheet. cells;//cell

Style 2

Aspose.Cells.Style style2 = workbook. Styles[workbook. Styles.add ()];//new style

Style2. HorizontalAlignment = textalignmenttype.center;//text centered

Style2. VerticalAlignment = Textalignmenttype.center;

Style2. Font.Name = "Song body";//Text font

Style2. Font.Size = 12;//Text Size

Style2. Font.isbold = true;//Bold

Style3. BackgroundColor = System.Drawing.Color.Yellow;

Style2. istextwrapped = true;//cell contents Wrap

Style2. Borders[bordertype.leftborder]. LineStyle = Cellbordertype.thin;

Style2. Borders[bordertype.rightborder]. LineStyle = Cellbordertype.thin;

Style2. Borders[bordertype.topborder]. LineStyle = Cellbordertype.thin;

Style2. Borders[bordertype.bottomborder]. LineStyle = Cellbordertype.thin;
Cells. Setrowheight (3, 10);//Set high
Cells. Setcolumnwidth (Colnum-1, 50);//Set Wide

Cells[0, 2]. Putvalue ("style use")

Cells[0, 2]. Style = style2;//0 indicates line number, 2 indicates column number
Cells. Merge (1, 2, 3, 4);//Merge cell 1 represents the line number, 2 represents the column number, 3 represents the combined row number, and 4 indicates the number of columns merged; Change one of 3 or 4 to 1, indicating that rows or columns are not merged; Merge (1, 2, 3, 1); merge only three rows, not parallel


<summary>

Export method

</summary>

<param name= "Mcorinfo" > Information one </param>

<param name= "DS" > Info two </param>

public void Toexcel (M_corporationcirclesinfo mcorinfo,dataset DS)

{

Aspose.Cells.Workbook wk = new Aspose.Cells.Workbook ();

Wk. Open (System.Web.HttpContext.Current.Server.MapPath (@ "~\excel\abc.xls"));

AddExcelSHeet1 (wk, mcorinfo);

AddExcelSHeet2 (wk, DS);

Wk. Save (System.Web.HttpContext.Current.Server.MapPath (@ "~\excel\abcd.xls"));

Wk. Open (System.Web.HttpContext.Current.Server.MapPath (@ "~\excel\abcd.xls"));

Response.Write (wk. Worksheets[0]. Cells[2, 1]. Value.tostring ()); Red 01 means 1th sheet, cells[i,k] I means the number of rows K means the first few columns value is to read inside the value

}

<summary>

Export Information One

</summary>

<param name= "Cells" > current Excel sheet line number </param>

<param name= "Mcorinfo" > Information one </param>

private void AddExcelSHeet1 (Aspose.Cells.Workbook wk, M_corporationcirclesinfo mcorinfo)

{

Wk. Worksheets[0]. Cells[2, 1]. Putvalue (Mcorinfo.CompanySystem.ToString ());

Wk. Worksheets[0]. Cells[3, 1]. Putvalue (Mcorinfo. Enrolname.tostring ());

Wk. Worksheets[0]. Cells[3, 6]. Putvalue (Mcorinfo. Enronumber.tostring ());

Wk. Worksheets[0]. Cells[4, 1]. Putvalue (Mcorinfo. Principal.tostring ());

Wk. Worksheets[0]. Cells[4, 6]. Putvalue (Mcorinfo.OrgnaztionCode.ToString ());

Wk. Worksheets[0]. Cells[5, 1]. Putvalue (Mcorinfo. Place.tostring ());

Wk. Worksheets[0]. Cells[5, 6]. Putvalue (Mcorinfo. Enrotime.tostring ());

Wk. Worksheets[0]. Cells[6, 1]. Putvalue (Mcorinfo. Deaiinlieu.tostring ());

Wk. Worksheets[0]. Cells[6, 6]. Putvalue (Mcorinfo. Dealinterm.tostring ());

Wk. Worksheets[0]. Cells[7, 1]. Putvalue (Mcorinfo. Enrocapital.tostring ());

Wk. Worksheets[0]. Cells[7, 6]. Putvalue (Mcorinfo. Paiclupcapital.tostring ());

Wk. Worksheets[0]. Cells[8, 1]. Putvalue (Mcorinfo. Enrodepartment.tostring ());

Wk. Worksheets[0]. Cells[8, 6]. Putvalue (Mcorinfo. Enroaddress.tostring ());

Wk. Worksheets[0]. CELLS[10, 1]. Putvalue (Mcorinfo. Churchyardtypecode.tostring ());

Wk. Worksheets[0]. CELLS[10, 2]. Putvalue (Mcorinfo. Fremdnesstypecodeid.tostring ());

Wk. Worksheets[0]. CELLS[10, 3]. Putvalue (Mcorinfo. Fremdnesstypecode.tostring ());

Wk. Worksheets[0]. Cells[9, 5]. Putvalue (Mcorinfo. Enrotypecode.tostring ());

Wk. Worksheets[0]. CELLS[10, 7]. Putvalue (Mcorinfo. Industrytype.tostring ());

Wk. Worksheets[0]. CELLS[10, 8]. Putvalue (Mcorinfo. Industrylittletype.tostring ());

Wk. Worksheets[0]. CELLS[11, 1]. Putvalue (Mcorinfo. Dealinbound.tostring ());

Wk. Worksheets[0]. CELLS[13, 1]. Putvalue (Mcorinfo. Corporationsort.tostring ());

Wk. Worksheets[0]. CELLS[13, 4]. Putvalue (Mcorinfo. Manageleves.tostring ());

Wk. Worksheets[0]. CELLS[13, 6]. Putvalue (Mcorinfo. Superiormanage.tostring ());

Wk. Worksheets[0]. CELLS[14, 1]. Putvalue (Mcorinfo. Aptitudecircs.tostring ());

Wk. Worksheets[0]. CELLS[15, 1]. Putvalue (Mcorinfo. Qualify.tostring ());

Wk. Worksheets[0]. CELLS[16, 1]. Putvalue (Mcorinfo. Managedepart.tostring ());

Wk. Worksheets[0]. CELLS[16, 4]. Putvalue (Mcorinfo. Linkman.tostring ());

Wk. Worksheets[0]. CELLS[16, 7]. Putvalue (Mcorinfo. Contact.tostring ());

Wk. Worksheets[0]. CELLS[17, 1]. Putvalue (Mcorinfo. Linkaddress.tostring ());

Wk. Worksheets[0]. CELLS[17, 5]. Putvalue (Mcorinfo. Internetaddress.tostring ());

Wk. Worksheets[0]. CELLS[18, 1]. Putvalue (Mcorinfo. Rmark.tostring ());

}

<summary>

Export add information Two

</summary>

<param name= "Cells" > current Excel sheet line number <</param>

<param name= "DS" > Information content </param>

private void AddExcelSHeet2 (Aspose.Cells.Workbook wk, DataSet DS)

{

if (ds! = null)

{

datarow[] Werow = ds. Tables[0]. Select ("stockholderkind=1");

if (Werow. Length > 0)

{

int i = 2;

foreach (DataRow rows in Werow)//query

{

i++;

Wk. WORKSHEETS[1]. Cells[i, 1]. Putvalue (rows["Stockholdename"). ToString ());

Wk. WORKSHEETS[1]. Cells[i, 2]. Putvalue (rows["Stock").                ToString ()); }

}

datarow[] Yourow = ds. Tables[0]. Select ("stockholderkind=2");

if (Yourow. Length > 0)

{

int i = 2;

foreach (DataRow rows in Yourow)//query

{

i++;

Wk. WORKSHEETS[1]. Cells[i, 4]. Putvalue (rows["Stockholdename"). ToString ());

Wk. WORKSHEETS[1]. Cells[i, 5]. Putvalue (rows["Isor"). ToString ());

Wk. WORKSHEETS[1]. Cells[i, 6]. Putvalue (rows["Stock"). ToString ()); The Red 1 indicates the second sheet, cells[i,k] I means the first few rows K indicates the number of columns Putvalue is to write the value inside

}

}

}

}

<summary>

Import method

</summary>

public void Readexceltrade ()

{

Aspose.Cells.Workbook wk = new Aspose.Cells.Workbook ();

Wk. Open (System.Web.HttpContext.Current.Server.MapPath (@ "~\excel\ type with code. xls"));//Here is the file that needs to be imported

M_corporationregisteredtrade Mtrade = new M_corporationregisteredtrade ();

B_corporationregisteredtrade Btrade = new B_corporationregisteredtrade ();

for (int i = 1; I <= 149; i++)//equals sign for Excel data, which can be fixed by itself such as: 149, or it can read its equal sign by itself;

{

if (i > 149)

{

Mtrade. Corporationtypecode = wk. Worksheets[0]. Cells[i, 0]. Value.tostring (). Trim ();//Read the corresponding information in the file

Mtrade. type_name = wk. Worksheets[0]. Cells[i, 1]. Value.tostring (). Trim ();

Mtrade. P_corporationtypecode = wk. Worksheets[0]. Cells[i, 2]. Value.tostring (). Trim ();

Mtrade. Level = wk. Worksheets[0]. Cells[i, 3]. Value.tostring (). Trim ();

Mtrade. Rmark = "";

Btrade. ADD (Mtrade);

}

}

}

Aspose.Cells.dll Required References

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.