C # How to save an Excel file

Source: Internet
Author: User

M_objexcel = new excel. Application ();
M_objexcel.visible = true;

Excel. Workbook m_objbook = m_objexcel.application.workbooks.add (filewrite );
M_objbook = m_objexcel.workbooks.add (missing. value );

Excel. worksheet m_objsheet = (Excel. worksheet) (m_objbook.worksheets [1]);

M_objrange = m_objsheet.get_range ("A5", type. Missing );

// Two-dimensional array for storing report data
Object [,] objdate = new object [rownum, 9];

.......................

.......................
M_objrange = m_objsheet.get_range ("A5", missing. value );
M_objrange = m_objrange.get_resize (rownum, 9 );
// Horizontal alignment-right alignment
M_objrange.horizontalalignment = excel. xlhalign. xlhalignright;
// Text format
M_objrange.numberformat = "@";
M_objrange.value2 = objdate;

// Save and cast execl Resources

M_objbook.saved = true;
M_objexcel.displayalerts = false;

M_objsheet. _ saves (filewrite, missing. Value, missing. value,
Missing. Value, missing. value );
M_objbook.close (false, missing. Value, missing. value );
If (m_objexcel! = NULL)
{
M_objexcel.workbooks.close ();
M_objexcel.quit ();
System. runtime. interopservices. Marshal. releasecomobject (m_objexcel );
System. gc. Collect ();
}

If (m_objsheet! = NULL)
{
System. runtime. interopservices. Marshal. releasecomobject (m_objsheet );
System. gc. Collect ();
}
GC. Collect ();

This write can pass the vs2008 Test

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.