Application Ms Excel Xlsx

broken image


There are several ways to convert your Excel file from.xlsx to.xls format. Using the Save As function is the easiest way to convert your Excel file by performing the following steps: Open your workbook that you want to convert the format. Click File Save As. Get-Process Export-Excel c: temp ps.xlsx –Show. This example creates a ps.xlsx file, a workbook, a worksheet, a header row, and organizes all the data in rows and columns. The –Show parameter launches Excel and opens the ps.xlsx file. This is great (and it works with any data in PowerShell). The flat data is important, and so are the visuals.

In this article, we will see different ways to export data to Excel from a web application. It is very common task for web developers. Here are different approaches to do it in ASP.NET – C#:

Approach 1:

Using the Excel PIA (primary interop assemblies) to generate a spreadsheet server-side.

It needs Microsoft Office suite installed on your server which is not good. So it is NOT recommended.

Approach 2:

Using CSV/TSV content and save it to a file with a .xls extension.

If you don't need control over formatting, styles, or workbook structure, only need data in excel, this approach is good for you.

To convert Generic data to TSV (Tab Separated Values) Format, use following method:

and use following ASP.NET MVC action to generate excel:

For simplicity, I am using hard-coded sample data.

Read Also:Upload and Read Excel File (.xls, .xlsx) in ASP.NET MVC

Approach 3:

Battlegrounds playerunknown ps4. Generating HTML content and save it to a file with a .xls extension.

To convert Generic data to HTML Format with Table control, use following method:

In above method, we defined yellow header background color. use the above method to export data like below

You can use ASP.NET GridView directly(instead of table).

If you want to export to excel from ASP.NET Razor View then use following action:

add a razor view of above action and use following code:

In this approach, the logic is same to generate HTML, but the ways are different.

Approach 4:

When you open .xls file generated with Approach 2 & 3, you will get warning because of format difference. It is a bit annoyance.

EPPlus for .XLS

In this Approach, we will use free open source library EPPlus to export the content. It writes Excel 2007/2010 files using the Open Office Xml format (xlsx) only.

Run following command in the Package Manager Console to install EPPlus:

install-package epplus

Use following method for exporting data:

You can see how easy it is in .xlsx format. This library allows you to set worksheet properties, custom and conditional formatting, Cell Ranges and Cell styling (Border, Color, Fill, Font, Number, Alignments),Formula calculation .etc.

If you have datatable as datasource, use following to load it

NPOI for .XLS & .XLSX

If you want to generate both .xls and .xlsx files from single library then use NPOI library. This project is the .NET version of POI from Apache Foundation. NPOI can read and write xls (Excel 97-2003), xlsx(Excel 2007+). To install NPOI, run the following command in the Package Manager Console:

Install-Package NPOI

Microsoft excel applications

Add following method:

Note: In above method, It is clearly visible response syntax differences (ContentType, Header and Write) between xls and xlsx.

Consider following datatable as datasource:

To export in .xls format:

To export in .xlsx format:

Conclusion:

Free Excel Applications

This post explains the different ways to export data in excel (.xls and .xlsx) format and their pros and cons. Everyone piano music. If you want your plain data in spreadsheet then approach 2 is good. If you are exporting data from any HTML element or you need some data formatting then approach 3 is good. If you need xlsx format then I recommend EPPlus. If you have to do a lot of operations on Excel and need support of both formats then NPOI is the best option for you, but it is very heavy.

Excel Xlsx To Xls Converter

Hope, It helps. Feel free to share your opinion in comment box.





broken image