ASP. NET-read and write Excel-myxls-instructions for use of third-party controls

Source: Internet
Author: User

From http://hi.baidu.com/nirvanan/blog/item/175abc002c4bf016728da5ae.html

 

Third-party tool download: http://myxls.in2bits.org/WIKI/Downloads.ashx

1. You do not need to install Excel on the server.

2. a lot of information on the Internet is only set with no value. Here I have compiled some experience on using this set of controls.

3. It is good if it is only written but not valid.
1. This third-party control sometimes does not support breakpoint debugging. Otherwise, an error occurs: [NoSource code]
2. If you want to set a value, you need to initialize unused cells with a Null String. Otherwise, the cells will be automatically indented in the internal logic. For example, if you set () and (), the values can only be () and)

========================================================== ================================

Org. in2bits. myxls. xlsdocument XLS = new org. in2bits. myxls. xlsdocument ();
XLS. filename = "myxls Hello world.xls"; // a file name must be set.
// Add a worksheet and set its name
Org. in2bits. myxls. worksheet sheet = XLS. Workbook. worksheets. addnamed ("Hello, world! ");
// Obtain the Cell Object
Org. in2bits. myxls. Cells = sheet. cells;
Cells. Add (1, 1, "hello"); // set the value
Cells. Add (1, 3, "world"); // set the value
// Obtain the row object.
Org. in2bits. myxls. rows = sheet. Rows;
// Obtain the first row. The subscript starts from 1 instead of 0.
Org. in2bits. myxls. Row row = rows [ushort. parse ("1") ">;
// Subscript starts from 1, instead of 0
Org. in2bits. myxls. Cell cell = row. getcell (ushort. parse ("2 "));
// If it is null, the initialization is a null string; otherwise, the tostring () error occurs.
Object OBJ = cell. value = NULL? "": Cell. value;
// XLS. Save (@ "D: \"); // save it to a path
XLS. Send (); // send to client
// Response. Write (Int. parse (obj. tostring ()));

========================================================== ==============================
Iii. Merge:

Cells. Add (2, 1, "test ");
Cells. Merge (2, 2, 3 );

Parameter type: (minimum row, maximum row, minimum column, and maximum column)
This is different from our usual concepts (Starting abscissa, starting ordinate, ending abscissa, and ending ordinate ).
After merging, calculate a cell, and the style is the grid occupied,
However, a value can only represent one grid.
After setting cells. Merge,
Take cells. Add (2, 4, "test"); you have to get (2, 2) instead of (2, 4 ).

[The automatic indent problem mentioned in "2" and "3" is the solution to initialize unused cells]
Cells. Add (2, 1, "test ");
Cells. Add (2, 2 ,"");
Cells. Add (2, 3 ,"");
Cells. Merge (2, 2, 3 );

After setting cells. Merge,

Take cells. Add (2, 4, "test"); Take (2, 4) instead of (2, 2 ).

 
All right, if you can solve the issue of value statistics on the database, try to operate on the database.
It is best to take less values in Excel.
 

Iv. style:

Org. in2bits. myxls. XF = XLS. newxf (); // format object
XF. Font. Bold = true; // bold
XF. horizontalalignment = org. in2bits. myxls. horizontalalignments. centered; // center in the left-right corner
XF. verticalalignment = org. in2bits. myxls. verticalignments. centered; // center online
XF. bottomlinestyle = ushort. parse ("2"); // The bottom line is thick.
XF. bottomlinecolor = org. in2bits. myxls. colors. default0c; // the color of the bottom line.
XF. Font. Height = 400; // auto height, which is also the size
Cells. Add (2, 4, "test text", XF); // set the value

It can also be used as follows:

Org. in2bits. myxls. Cell cell = cells. Add (2, 4, "test text", XF );
Cell. Font. Bold = true;
Cell. horizontalalignment = org. in2bits. myxls. horizontalalignments. centered;
Cell. verticalignment = org. in2bits. myxls. verticalignments. centered;
Cell. bottomlinestyle = ushort. parse ("2 ");
Cell. bottomlinecolor = org. in2bits. myxls. colors. default0c;

The supported settings are relatively simple.
========================================================== ==================================

Excel. dll is rarely used, and Excel must be installed on the server. It is difficult to support and secure download to the client. It is not recommended by the official team:

Http://support.microsoft.com/kb/257757/en-us said like this:

 

Microsoft does not currently recommend, and does not support, automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, Asp. net, DCOM, and NT Services), Because office may exhibit unstable behavior and/or deadlock when office is run in this environment.

========================================================== =====

Office XML is officially promoted:

Http://support.microsoft.com/kb/931866/

Client Requirements

Microsoft Visual Studio 2005 or Microsoft Visual C #2005
. NET Framework 3.0
2005 extension for. NET Framework Visual Studio 3.0
Excel 2007 or Word 2007
In the above mode, you don't need to install Excel on the server. I haven't tried it yet.

However, the client must install Excel 2007 or Word 2007

 

I found some information on the Internet and failed to upgrade to vs2005 +. net3.0 Based on vs2005 +. NET 2.0!

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.