C # Read and Write Data to excel cells (including some basic operations on Excel)

Source: Internet
Author: User
The following are some basic operations on Excel: 1. Import the Excel class library to the project, for example, c: \ Program Files \ Microsoft Office \ offiece11 \ excel.exe 2: Introduction of the naming control: using Microsoft. office. interOP. excel; 3: if an existing Excel file is operated, application APP = new application (); workbook wbook = app. workbooks. open ("C: \ temp.xls", type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing); worksheet = (worksheet) wbook. worksheets [1]; 4: Create an Excel file: Application APP = new application (); workbook wbook = app. workbook. add (type. missing); worksheet = (worksheet) wbook. worksheets [1]; 5: Set the content in a cell: Worksheet. cells [1, 2] = "column content" 6 read the content of a cell string temp = (range) worksheet. cells [1, 2]). text; 7. Set the Excel format in a cell. range rtemp = worksheet. get_range ("A1", "A1"); rtemp. font. name = ""; rtemp. font. fontstyle = "bold"; rtemp. font. size = 5; 8 Save the new content: Worksheet. saveas ("C: \ temp.xls", type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing );

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.