When Asp.net imports data from an Excel file, the following error message is displayed: The format is not correct.

Source: Internet
Author: User
This problem occurs when Excel is used for import and export in a recent project,

After exporting the data to an Excel file, modify some data and then import the Excel file.

The error message "not an expected format error" is displayed ". After detailed troubleshooting, find the exported Excel File Format

Not a true Microsoft Office Excel file format, but an HTML Excel file,

You can use NotePad to open the Excel file for verification,

If the file is garbled, it indicates the file format of Microsoft Office Excel, which is correct for File Import.

If it is not garbled, you will find some HTML FormatCodeWhen the Excel file is imported, the above error is reported.

Then, check the cause and find that if you use httpcontext. current. response Method, change the contenttype type to output the Excel file, then the exported Excel file format is HTML type Excel file.

If you use the Excel component to export an Excel file, the exported Excel file format is normal and can be imported.

This problem is basically solved, and I hope to help my friends who encounter the same problem!

In addition, if you open the exported Excel file in HTML format and save it as a correct Excel file format, it can also be imported normally.

 

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.