Excel (4) format and formula used in ASP. NET

Source: Internet
Author: User

Now that a cell object is available, let's read the cell data:

Excel. range cell = (Excel. range) range. get_item (R, c); // get the cell object if (bool) cell. hasformula) // The unit format is formula {// cell_elem is the xmlelement object cell_elem.setattribute ("hasformula", "true"); cell_elem.setattribute ("formula", cell. formula. tostring (); // obtain the formula content cell_elem.setattribute ("value", cell. text. tostring (); // Note: cell. text is the formula calculation result + format setting result, not necessarily equal to the formula expression ....} // switch (INT) cell alignment in unit format. horizontalalignment) // horizontal alignment {Case (INT) excel. constants. xlcenter: cell_elem.setattribute ("align", "center"); break; // center case (INT) excel. constants. xlleft: cell_elem.setattribute ("align", "Left"); break; // Use Case (INT) Excel to the left. constants. xlright: cell_elem.setattribute ("align", "right"); break; // default to the right: cell_elem.setattribute ("align", ""); break; // default}
Switch (int) cell. verticalAlignment) // vertical alignment {case (int) Excel. constants. xlTop: cell_elem.SetAttribute ("valign", "top"); break; // top case (int) Excel. constants. xlCenter: cell_elem.SetAttribute ("valign", "middle"); break; // center case (int) Excel. constants. xlBottom: cell_elem.SetAttribute ("valign", "bottom"); break; // default: cell_elem.SetAttribute ("valign", ""); break; // default}
// Font property {Excel. font font = cell. font; // note: the reference to the font will generate a count. Do not forget to destroy it cell_elem.SetAttribute ("font-family", Font. name. toString (); // font name if (font. color. getType ()! = Typeof (System. DBNull) // The color may be null {colorVal = (int) (double) font. color; // convert colorVal = colorVal> 16 | colorVal & 0xFF00 | colorVal <16; // It was originally in BGR mode and needs to be converted to RGB mode} else colorVal = 0; // black cell_elem.SetAttribute ("font-color", string. format ("# {0: X2} {1: X2} {2: X2}", colorVal & 0xFF, (colorVal> 8) & 0xFF, (colorVal> 16) & 0xFF); // converts it to # RRGGBB, which is used by the HTML element cell_elem.SetAttribute ("font-italic ", Font. italic. toString (); // Font. italic type: Boolean cell_elem.SetAttribute ("font-bold", font. bold. toString (); // same as cell_elem.SetAttribute ("font-size", font. size. getType ()! = Typeof (System. DBNull )? // The font size is pt (point) font. size. toString () + "pt": "12pt"); cell_elem.SetAttribute ("font-strikethrough", font. strikethrough. toString (); // The Central dash releaseComObject (font); // release font = null ;}
// Process cell merging if (bool) cell. MergeCells) // is the merged cell? {Excel. range ma = (Excel. range) cell. mergeArea; // obtain the merged area Excel. range macol = ma. columns; // merge the included rows in Excel. range marow = ma. rows; // merge the contained columns cell_elem.SetAttribute ("rowspan", marow. count. toString (); // row span cell_elem.SetAttribute ("colspan", macol. count. toString (); // column span cell_elem.SetAttribute ("width", ma. width. toString () + "pt"); // The cell_elem.SetAttribute ("height", ma. height. toString () + "pt"); releaseComObject (marow); marow = null; // do the releaseComObject (macol); macol = null; releaseComObject (ma ); ma = null;
....} Else {// cell_elem.SetAttribute ("colspan", "1") is not merged; // Normal SPAN cell_elem.SetAttribute ("rowspan", "1"); cell_elem.SetAttribute ("width", cell. width. toString () + "pt"); // cell_elem.SetAttribute ("height", cell. height. toString () + "pt ");
    ....}
Row_elem.AppendChild (cell_elem); // insert a cell in XML to the column element releaseComObject (cell); // release cell = null;

 

 

 

 

 

 

 

 

 

 

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.