Data grid to excel

Всем доброго времени суток!
Хотел бы поделиться своим практическим примером экспортирования данных из таблицы DataGridView в Microsoft Excel.
Потратив около пары часов на поиск нормального примера, такового не обнаружил… Немного поэкспериментировав с имеющимся кодом, получил нужный результат!
Итак, для использования Excel приложения необходимо подключить соответствующие references, а именно:

  1. «Microsoft Office 11.0 Object Library» расположенного во вкладке COM компонентов
  2. «Microsoft.Office.Interop.Excel» расположенного во вкладке .Net компонентов

Далее прописываем
using Microsoft.Office.Interop.Excel;
Теперь нам доступен класс для запуска Excel из нашей программы. Создадим объект класса:
Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
Создаем рабочую книгу:
ExcelApp.Application.Workbooks.Add(Type.Missing);
Нам доступно редактирование некоторых параметров, в качестве примера изменим ширину столбцов:
ExcelApp.Columns.ColumnWidth = 15;
Задать значение ячейки можно так:
ExcelApp.Cells[1, 1 ]= "№п/п";
Для переноса данных применил такой цикл (dgvHadTovar — это имя моего компонента DataGridView):
for (int i = 0; i < dgvHadTovar.ColumnCount; i++)
{
for (int j = 0; j < dgvHadTovar.RowCount; j++)
{
ExcelApp.Cells[j + 2, i + 1 ] = (dgvHadTovar[i,j].Value).ToString();
}
}

j + 2, потому что первая строка отведена для подписей столбцов!
И для отображения полученного результата, необходимо показать документ:
ExcelApp.Visible = true;

В итоге получилась такая функция:

private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
ExcelApp.Application.Workbooks.Add(Type.Missing);
ExcelApp.Columns.ColumnWidth = 15;

ExcelApp.Cells[1, 1 ]= "№п/п";
ExcelApp.Cells[1, 2 ]= "Число";
ExcelApp.Cells[1, 3 ]= "Название";
ExcelApp.Cells[1, 4 ]= "Количество";
ExcelApp.Cells[1, 5 ]= "Цена ОПТ";
ExcelApp.Cells[1, 6 ]= "Цена Розница";
ExcelApp.Cells[1, 7] = "Сумма";

for (int i = 0; i < dgvHadTovar.ColumnCount; i++)
{
for (int j = 0; j < dgvHadTovar.RowCount; j++)
{
ExcelApp.Cells[j + 2, i + 1 ] = (dgvHadTovar[i,j].Value).ToString();
}
}
ExcelApp.Visible = true;
}

  • Download demo project — 3.39 Kb

Introduction

DataGrid is one of the most coolest controls in ASP.NET. One thing that all developers need is to put the DataGrid data into an Excel sheet. In this article I will show you how you can export your DataGrid data to an Excel file, a Word file and also a text file.

Exporting DataGrid to Excel might sound complex but it’s pretty simple. Let’s see how this can be done.

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

myDataGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

The code given above is the complete code to export a DataGrid to an Excel file:

  • Response.AddHeader is letting ASP.NET know that we are exporting to a file which is named FileName.xls.
  • Response.ContentType denotes the type of the file being exported.
  • myDataGrid.RenderControl(htmlWrite) writes the data to the HtmlTextWriter.
  • Response.Write(stringWrite.ToString()); sends the request to the response stream.

As you can see, exporting a DataGrid to an Excel file is pretty simple.

Exporting the DataGrid to a Word file

You can also export a DataGrid to a Word file. You might ask a question that why would anyone like to do that. If you have a Word document which needs a table, then you can simply export the table from the DataGrid to the Word document. The code is similar to the above with minor changes.

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.doc");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.word";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

myDataGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

Exporting a DataGrid to a Text File

Sometimes you need to export a DataGrid to a Text file. In this case you need to iterate through the DataSet and concatenate the text to a string or more precisely a StringBuilder object. Let’s see how this can be done:

Database db = DatabaseFactory.CreateDatabase();
DBCommandWrapper selectCommandWrapper = 
   db.GetStoredProcCommandWrapper("sp_GetLatestArticles");
DataSet ds = db.ExecuteDataSet(selectCommandWrapper);
StringBuilder str = new StringBuilder();

for(int i=0;i<=ds.Tables[0].Rows.Count - 1; i++)
{
  for(int j=0;j<=ds.Tables[0].Columns.Count - 1; j++)
  {
      str.Append(ds.Tables[0].Rows[i][j].ToString());
  }

  str.Append("<BR>");
}

Response.Clear();
Response.AddHeader("content-disposition", 
         "attachment;filename=FileName.txt");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.text";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = 
              new HtmlTextWriter(stringWrite);

Response.Write(str.ToString());
Response.End();

The important thing to note is the two for loops that iterate through the DataSet and append the rows into the StringBuilder object.

Format Issue when Exporting DataGrid to Excel

I would like to thank Sonu Kapoor for helping me with the Format issue in exporting a DataGrid to Excel and Juss for providing the code.

When you export a DataGrid to Excel it loses its format. This means that maybe your DataGrid has a string field which consisted of numbers, say ‘002345’. But when you export the grid and see it in an Excel file you will find that the number changed to ‘2345’.

You can solve this problem using Cascading Style Sheets.

Code provided by Juss:

Dim strFileName, strFilePath AsString
Dim oStringWriter AsNew System.IO.StringWriter
Dim oHtmlTextWriter AsNew System.Web.UI.HtmlTextWriter(oStringWriter)
Dim objStreamWriter As StreamWriter
Dim strStyle AsString = "<style>.text { mso-number-format:@; } </style>"
objStreamWriter = File.AppendText(strFilePath)
DataGrid1.RenderControl(oHtmlTextWriter)
objStreamWriter.WriteLine(strStyle)
objStreamWriter.WriteLine(oStringWriter.ToString())
objStreamWriter.Close()

Most of you might be thinking about that «mso-number-format» stuff in between the code. This is the style in which the column will be exported. For this reason, you need to inject the attribute into the DataGrid column for which you want to change the display format.

DataGrid1.DataBind()
Dim strStyle AsString = "<style>.text { mso-number-format:@; } </style>"
For intTemp AsInteger = 1 To ds.Tables(0).Rows.Count - 1
   DataGrid1.Items(intTemp).Cells(0).Attributes.Add("class", "text")
Next

You can export in many formats. All you need to know is the mso-number-format:@;. You can easily find the format by opening an Excel file and typing a number in one of the cells. Now if you want to save this number as a Social Security Pattern (xxx-xx-xxxx), right click on the cell and select a pattern that saves it as a Social Security Number. Next save the Excel file to XML format. Open the XML file in Notepad and see what style the column SSN uses. The SSN style is something like this: mso-number-format:000-00-0000.

Simply substitute the new style in the strStyle variable and that’s it.

For a complete discussion on this issue, please visit this link.

I hope you liked the article, happy coding!

I was also looking for something simillar to help export the data in the datagrid into excel, but found nothing which works.
Atlast I just converted the content of the DataGrid into a 2D array of string and exported it using the interop dll.

The code looks something like this:

    Excel.Application xlApp;
    Excel.Workbook xlWorkBook;
    Excel.Worksheet xlWorkSheet;
    object misValue = System.Reflection.Missing.Value;
    Excel.Range rangeToHoldHyperlink;
    Excel.Range CellInstance;
    xlApp = new Excel.Application();
    xlWorkBook = xlApp.Workbooks.Add(misValue);

    xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
    xlApp.DisplayAlerts = false;
    //Dummy initialisation to prevent errors.
    rangeToHoldHyperlink = xlWorkSheet.get_Range("A1", Type.Missing);
    CellInstance = xlWorkSheet.get_Range("A1", Type.Missing);

    for (int i = 0; i < NumberOfCols; i++)
    {
            for (int j = 0; j <= NumberOfRows; j++)
            {
                xlWorkSheet.Cells[j + 1, i + 1] = DataToWrite[j][i];
            }
     }

If you are looking for some formating, they are also supported in this. I wanted to add a hyperlink and the following code does that:

 CellInstance = xlWorkSheet.Cells[j + 1, i + 1];

                xlWorkSheet.Hyperlinks.Add(
                    CellInstance,
                    DataToWrite[j][i],
                    Type.Missing,
                    "Hover Text Comes Here",
                    "Text to be displayed");

If you want the first row to be the header, you can highlight them as follows:

Excel.Range Range1 = xlWorkSheet.get_Range("A1");
Range1.EntireRow.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
Range1.EntireRow.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightSkyBlue);
Range1.EntireRow.Font.Size = 14;
Range1.EntireRow.AutoFit();

Finally to Save the excel in a desired path:

xlWorkBook.SaveAs(@FilePath, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close();

The reference to the interop is added as follows:

Right Click on the Project name -> Click "Add reference" -> Goto "COM" tab -> Search for "Microsoft Excel Object Library" click "OK" to add the reference.

You must be using the following namespace :

using Excel = Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;

Easily export the rows in various file formats such as CSV, Excel, or PDF.

Enabling export

Default Toolbar

To enable the export menu, pass the GridToolbar component in the Toolbar component slot.

Press Enter to start editing

Custom Toolbar

The export menu is provided in a stand-alone component named GridToolbarExport. You can use it in a custom toolbar component as follows.

function CustomToolbar() {
  return (
    <GridToolbarContainer>
      <GridToolbarExport />
    </GridToolbarContainer>
  );
}

Export options

By default, the export menu displays all the available export formats, according to your license, which are

  • Print
  • CSV
  • Excel
  • Clipboard (🚧 Not delivered yet)

You can customize their respective behavior by passing an options object either to the GridToolbar or to the GridToolbarExport as a prop.

<DataGrid slotProps={{ toolbar: { csvOptions } }} />

// same as

<GridToolbarExport csvOptions={csvOptions} />

Each export option has its own API page:

  • csvOptions
  • printOptions

Disabled format

You can remove an export format from the toolbar by setting its option property disableToolbarButton to true.
In the following example, the print export is disabled.

<DataGrid
  slotProps={{ toolbar: { printOptions: { disableToolbarButton: true } } }}
/>

Exported columns

By default, the export will only contain the visible columns of the data grid.
There are a few ways to include or hide other columns.

  • Set the disableExport attribute to true in GridColDef for columns you don’t want to be exported.
<DataGrid columns={[{ field: 'name', disableExport: true }, { field: 'brand' }]} />
  • Set allColumns in export option to true to also include hidden columns. Those with disableExport=true will not be exported.
<DataGrid slotProps={{ toolbar: { csvOptions: { allColumns: true } } }} />
  • Set the exact columns to be exported in the export option. Setting fields overrides the other properties. Such that the exported columns are exactly those in fields in the same order.
<DataGrid slotProps={{ toolbar: { csvOptions: { fields: ['name', 'brand'] } } }} />

Exported rows

By default, the data grid exports the selected rows if there are any.
If not, it exports all rows except the footers (filtered and sorted rows, according to active rules), including the collapsed ones.

Alternatively, you can set the getRowsToExport function and export any rows you want, as in the following example.
The grid exports a few selectors that can help you get the rows for the most common use-cases:

Selector Behavior
gridRowIdsSelector The rows in their original order.
gridSortedRowIdsSelector The rows after applying the sorting rules.
gridFilteredSortedRowIdsSelector The rows after applying the sorting rules, and the filtering rules.
gridExpandedSortedRowIdsSelector The rows after applying the sorting rules, the filtering rules, and without the collapsed rows.
gridPaginatedVisibleSortedGridRowIdsSelector The rows after applying the sorting rules, the filtering rules, without the collapsed rows and only for the current page (Note: If the pagination is disabled, it will still take the value of page and pageSize).

When using Row grouping, it can be useful to remove the groups from the CSV export.

CSV export

Exported cells

When the value of a field is an object or a renderCell is provided, the CSV export might not display the value correctly.
You can provide a valueFormatter with a string representation to be used.

<DataGrid
  columns={[
    {
      field: 'progress',
      valueFormatter: ({ value }) => `${value * 100}%`,
      renderCell: ({ value }) => <ProgressBar value={value} />,
    },
  ]}
/>

File encoding

You can use csvOptions to specify the format of the export, such as the delimiter character used to separate fields, the fileName, or utf8WithBom to prefix the exported file with UTF-8 Byte Order Mark (BOM).
For more details on these options, please visit the csvOptions API page.

<GridToolbarExport
  csvOptions={{
    fileName: 'customerDataBase',
    delimiter: ';',
    utf8WithBom: true,
  }}
/>

Print export

Modify the data grid style

By default, the printed grid is equivalent to printing a page containing only the data grid.
To modify the styles used for printing, such as colors, you can either use the @media print media query or the pageStyle property of printOptions.

For example, if the data grid is in dark mode, the text color will be inappropriate for printing (too light).

With media query, you have to start your sx object with @media print key, such that all the style inside are only applied when printing.

<DataGrid
  sx={{
    '@media print': {
      '.MuiDataGrid-main': { color: 'rgba(0, 0, 0, 0.87)' },
    },
  }}
  {/* ... */}
/>

With pageStyle option, you can override the main content color with a more specific selector.

<DataGrid
  slotProps={{
    toolbar: {
      printOptions:{
        pageStyle: '.MuiDataGrid-root .MuiDataGrid-main { color: rgba(0, 0, 0, 0.87); }',
      }
    }
  }}
  {/* ... */}
/>

Customize grid display

By default, the print export display all the DataGrid. It is possible to remove the footer and the toolbar by setting respectively hideFooter and hideToolbar to true.

<GridToolbarExport
  printOptions={{
    hideFooter: true,
    hideToolbar: true,
  }}
/>

For more option to customize the print export, please visit the printOptions API page.

Custom export format

You can add custom export formats by creating your own export menu.
To simplify its creation, you can use <GridToolbarExportContainer /> which contains the menu logic.
The default <GridToolbarExport /> is defined as follow:

const GridToolbarExport = ({ csvOptions, printOptions, ...other }) => (
  <GridToolbarExportContainer {...other}>
    <GridCsvExportMenuItem options={csvOptions} />
    <GridPrintExportMenuItem options={printOptions} />
  </GridToolbarExportContainer>
);

Each child of the <GridToolbarExportContainer /> receives a prop hideMenu to close the export menu after the export.
The demo below shows how to add a JSON export.

Excel export

This feature relies on exceljs.
The Excel export allows translating columns’ type and tree structure of a DataGrid to an Excel file.

Columns with types 'boolean', 'number', 'singleSelect', 'date', and 'dateTime' are exported in their corresponding type in Excel. Please ensure the rows values have the correct type, you can always convert them as needed.

Customization

Customizing the columns

You can use the columnsStyles property to customize the column style.
This property accepts an object in which keys are the column field and values an exceljs style object.

This can be used to specify value formatting or to add some colors.

<GridToolbarExport
  excelOptions={{
    columnsStyles: {
      // replace the dd.mm.yyyy default date format
      recruitmentDay: { numFmt: 'dd/mm/yyyy' },
      // set this column in green
      incomes: { font: { argb: 'FF00FF00' } },
    },
  }}
/>

Customizing the document

You can customize the document using two callback functions:

  • exceljsPreProcess called before adding the rows’ dataset.
  • exceljsPostProcess called after the dataset has been exported to the document.

Both functions receive { workbook, worksheet } as input.
They are exceljs objects and allow you to directly manipulate the Excel file.

Thanks to these two methods, you can modify the metadata of the exported spreadsheet.
You can also use it to add custom content on top or bottom of the worksheet, as follows:

function exceljsPreProcess({ workbook, worksheet }) {
  workbook.created = new Date(); // Add metadata
  worksheet.name = 'Monthly Results'; // Modify worksheet name

  // Write on first line the date of creation
  worksheet.getCell('A1').value = `Values from the`;
  worksheet.getCell('A2').value = new Date();
}

function exceljsPostProcess({ worksheet }) {
  // Add a text after the data
  worksheet.addRow(); // Add empty row

  const newRow = worksheet.addRow();
  newRow.getCell(1).value = 'Those data are for internal use only';
}

// ...

<GridToolbarExport
  excelOptions={{
    exceljsPreProcess,
    exceljsPostProcess,
  }}
/>;

Since exceljsPreProcess is applied before adding the content of the data grid, you can use it to add some informative rows on top of the document.
The content of the data grid will start on the next row after those added by exceljsPreProcess.

To customize the rows after the data grid content, you should use exceljsPostProcess. As it is applied after adding the content, you can also use it to access the generated cells.

In the following demo, both methods are used to set a custom header and a custom footer.

Using a web worker

Instead of generating the Excel file in the main thread, you can delegate the task to a web worker.
This method reduces the amount of time that the main thread remains frozen, allowing to interact with the grid while the data is exported in background.
To start using web workers for the Excel export, first you need to create a file with the content below.
This file will be later used as the worker script, so it must be accessible by a direct URL.

// in file ./worker.ts
import { setupExcelExportWebWorker } from '@mui/x-data-grid-premium';

setupExcelExportWebWorker();

The final step is to pass the path to the file created to GridToolbarExport or the API method:

<GridToolbarExport
  excelOptions={{
    worker: () => new Worker('/worker.ts'),
  }}
/>;

// or

apiRef.current.exportDataAsExcel({
  worker: () => new Worker('/worker.ts'),
});

Since the main thread is not locked while the data is exported, it is important to give feedback for users that something is in progress.
You can pass a callback to the onExcelExportStateChange prop and display a message or loader.
The following demo contains an example using a Snackbar:

🚧 Clipboard

apiRef

The grid exposes a set of methods that enables all of these features using the imperative apiRef. To know more about how to use it, check the API Object section.

CSV

Print

Excel

  • Home
  • Articles

Datagrid is one of the most coolest controls in the Asp.net. One thing that all developers need is to put the data grid data into excel sheet. In this article I will show you that how you can export your datagrid data to Excel file, Word file and also Text file.

 Introduction:

Datagrid is one of the most coolest controls in the Asp.net. One thing that all developers need is to put the data grid data into excel sheet. In this article I will show you that how you can export your datagrid data to Excel file, Word file and also Text file.

Exporting datagrid to Excel:

Exporting datagrid to excel might sounds complex but its pretty simple. Let’s see how this can be done.

Response.Clear();

Response.AddHeader(«content-disposition», «attachment;filename=FileName.xls»);

Response.Charset = «»;

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = «application/vnd.xls»;

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

myDataGrid.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();

The code given above is the complete code to export the datagrid to excel file.

  • Response.AddHeader is letting Asp.net know that we are exporting a file which is named FileName.xls
  • Response.ContentType denotes the type of the file being exported
  • myDataGrid.RenderControl(htmlWrite) which writes the data to the HtmlTextWriter
  • Response.Write(stringWrite.ToString()); which send the request to the response stream.

As you can see exporting the datagrid to excel is pretty simple.

Exporting the datagrid to word file:

You can also export the datagrid to the word file. You might ask a question that why would anyone like to do that. If you have a word document which needs table than you can simple export the table from the datagrid to the word document. The code is similar to the above with little minor changes.

Response.Clear();

Response.AddHeader(«content-disposition», «attachment;filename=FileName.doc«);

Response.Charset = «»;

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = «application/vnd.word«;

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

myDataGrid.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();

  • The only changes we made is in bold. 

Exporting the datagrid to a Text File:

Sometimes you need to export the whole datagrid to a text file. In this case you need to iterate through the dataset and concatenate the text to string or more precisely StringBuilder object. Let’s see how this can be done.

Database db = DatabaseFactory.CreateDatabase();

DBCommandWrapper selectCommandWrapper = db.GetStoredProcCommandWrapper(«sp_GetLatestArticles»);

DataSet ds = db.ExecuteDataSet(selectCommandWrapper);

StringBuilder str = new StringBuilder();

for(int i=0;i<=ds.Tables[0].Rows.Count — 1; i++)

{

for(int j=0;j<=ds.Tables[0].Columns.Count — 1; j++)

{

str.Append(ds.Tables[0].Rows[i][j].ToString());

}

str.Append(«<BR>»);

}

Response.Clear();

Response.AddHeader(«content-disposition», «attachment;filename=FileName.txt«);

Response.Charset = «»;

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = «application/vnd.text«;

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

Response.Write(str.ToString());

Response.End();

The important thing to note is the two for loops that iterates through the dataset and append the rows into the StringBuilder object.

I would like to thank Sonu Kapoor for helping me with the Format issue in Exporting DataGrid to Excel and Juss for providing the code.

Format Issue when Exporting datagrid to Excel:

When you export the datagrid to Excel it looses it format. It means that maybe your datagrid has string field which consisted of numbers say ‘002345’. But when you export the grid and see it in excel file you will find that the number changed to ‘2345’.

You can solve this problem using Cascading Style Sheets.

Code provided by Juss:

Dim strFileName, strFilePath AsString
Dim
oStringWriter AsNew System.IO.StringWriter
Dim oHtmlTextWriter AsNew System.Web.UI.HtmlTextWriter(oStringWriter)
Dim objStreamWriter As StreamWriter
Dim strStyle AsString = «<style>.text { mso-number-format:@; } </style>»
objStreamWriter = File.AppendText(strFilePath)
DataGrid1.RenderControl(oHtmlTextWriter)
objStreamWriter.WriteLine(strStyle)
objStreamWriter.WriteLine(oStringWriter.ToString())
objStreamWriter.Close()

Most of you might be thinking that what is that mso-number-format stuff in between the code. This is the style in which the column will be exported. For this reason you need to inject the attribute into the datagrid column for which you want to change the display format.

DataGrid1.DataBind()
Dim strStyle AsString = «<style>.text { mso-number-format:@; } </style>»
For intTemp AsInteger = 1 To ds.Tables(0).Rows.Count — 1
   DataGrid1.Items(intTemp).Cells(0).Attributes.Add(«class», «text»)
Next

You can export in many formats. All you need to know is the mso-number-format:@; . You can easily find the format by going opening excel file and typing the number in one of the cells. Now if you want to save this number as a Social Security Pattern (xxx-xx-xxxx), right click on the cell and select a pattern that saves it as a Social Security Number. Next save the Excel file to xml format. Open the xml file in notepad and see that column SSN uses what style. The SSN style is something like this: mso-number-format:000-00-0000.

Simply substitute the new style in the strStyle variable and that’s it.

For the complete discussion on this issue please visit the following like:

http://forums.asp.net/ShowPost.aspx?PageIndex=2&PostID=893621#893621

I hope you liked the article, happy coding !

Понравилась статья? Поделить с друзьями:
  • Data from web page to excel
  • Data from pdf to excel
  • Data from html to excel
  • Data from form to excel
  • Data from excel to labels