 |
|
 |
because use of data table instead of gridview and do not use of COM components or third party DLL
|
|
|
|
 |
|
 |
Great Vivek, excellent piece or code.
|
|
|
|
 |
|
 |
Thanks! I ended up converting the XLS part to VB.Net See below
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.IO
Imports System.Text
Public Class ExcelConverter
'/// <summary>
'/// To generate excel file.
'/// </summary>
'/// <param name="oDataTable"></param>
'/// <param name="directoryPath"></param>
'/// <param name="fileName"></param>
'/// <returns></returns>
Public Function Convert(ByVal oDataTable As DataTable, ByVal directoryPath As String, ByVal fileName As String)
Dim fullpath As String = ""
If (directoryPath.Substring(directoryPath.Length - 1, 1) = "\" Or directoryPath.Substring(directoryPath.Length - 1, 1) = "/") Then
fullpath = directoryPath + fileName
Else
fullpath = directoryPath + "\" + fileName
End If
Dim SW As StreamWriter
SW = File.CreateText(fullpath)
Dim oStringBuilder As New StringBuilder()
'/********************************************************
'* Start, check for border width
'* ******************************************************/
Dim borderWidth As Integer = 0
If (_ShowExcelTableBorder) Then
borderWidth = 1
End If
'/********************************************************
'* End, Check for border width
'* ******************************************************/
'/********************************************************
'* Start, Check for bold heading
'* ******************************************************/
Dim boldTagStart As String = ""
Dim boldTagEnd As String = ""
If (_ExcelHeaderBold) Then
boldTagStart = "<B>"
boldTagEnd = "</B>"
End If
'/********************************************************
'* End,Check for bold heading
'* ******************************************************/
oStringBuilder.Append("<Table border=" + borderWidth.ToString + ">")
'/*******************************************************************
'* Start, Creating table header
'* *****************************************************************/
oStringBuilder.Append("<TR>")
For Each oDataColumn As DataColumn In oDataTable.Columns 'Check back here
oStringBuilder.Append("<TD>" + boldTagStart + oDataColumn.ColumnName + boldTagEnd + "</TD>")
Next
oStringBuilder.Append("</TR>")
'/*******************************************************************
'* End, Creating table header
'* *****************************************************************/
'/*******************************************************************
'* Start, Creating rows
'* *****************************************************************/
For Each oDataRow As DataRow In oDataTable.Rows
oStringBuilder.Append("<TR>")
For Each oDataColumn As DataColumn In oDataTable.Columns
If IsNumeric(oDataRow(oDataColumn.ColumnName)) Then
oStringBuilder.Append("<TD align=right>" + oDataRow(oDataColumn.ColumnName).ToString + "</TD>")
Else
oStringBuilder.Append("<TD>" + oDataRow(oDataColumn.ColumnName).ToString + "</TD>")
End If
Next
oStringBuilder.Append("</TR>")
Next
'/*******************************************************************
'* End, Creating rows
'* *****************************************************************/
oStringBuilder.Append("</Table>")
SW.WriteLine(oStringBuilder.ToString())
SW.Close()
Return fullpath
End Function
Private _ShowExcelTableBorder As Boolean = False
' '/// <summary>
' '/// To show or hide the excel table border
' '/// </summary>
Public Property ShowExcelTableBorder() As Boolean
Get
Return _ShowExcelTableBorder
End Get
Set(ByVal value As Boolean)
_ShowExcelTableBorder = value
End Set
End Property
Private _ExcelHeaderBold As Boolean = True
' '/// <summary>
' '/// To make header bold or normal
' '/// </summary>
Public Property ExcelHeaderBold() As Boolean
Get
Return _ExcelHeaderBold
End Get
Set(ByVal value As Boolean)
_ExcelHeaderBold = value
End Set
End Property
End Class
|
|
|
|
 |
|
 |
Dear VS,
this is very useful for me. i need to apply the following:
* background color
* font styles
* row height
is it possible to apply? if so can you please send me the code?
thanks and regards,
dhanasekaran. g
chennai, india.
|
|
|
|
 |
|
 |
HI,
This article is very useful and also simple........ Indians are always great..........Proud to be Indian.......
Padmanabhan
|
|
|
|
 |
|
 |
Hello and thanks for your work, it has been very useful for me but I have found a little bug in ExcelConvertor.cs (I dont know if the same fail is present in CSVConvertor.cs because I havent used it). This is the fail: when I set ExcelHeaderBold I got an exception, i think is because ExcelHeaderBold = value; must be _ExcelHeaderBold = value; in the next function
public bool ExcelHeaderBold
{
get
{
return _ExcelHeaderBold;
}
set
{
ExcelHeaderBold = value;
}
}
|
|
|
|
 |
|
 |
This was just what I was looking for. I am newer to the web and asp.net and was looking to save some data out as a CSV.
Thanks!
Scott
|
|
|
|
 |
|
 |
Can we use this library for our college report generation application project. we are developing the same in VB.NEt. and facing issues with xport in XLS. as we also don't have Microsoft Excel installed. we use Open Office and Excel Viewer.
Thanks in advance.
|
|
|
|
 |
|
 |
Please use it, for any purpose.
Best Regards,
VS
|
|
|
|
 |
|
 |
Hi,
you can try this Excel C# / VB.NET component. If you are not generating large Excel files, you can use it for free. It works without Excel Automation which makes it ideal for Excel ASP.NET applications:
Here is an Excel VB.NET sample how to export DataTable to browser:
Dim people As DataTable = DirectCast(Session("people"), DataTable)
Dim ef As New ExcelFile()
Dim ws As ExcelWorksheet = ef.Worksheets.Add("DataSheet")
ws.InsertDataTable(people, "A1", True)
Response.Clear()
Select Case Me.RadioButtonList1.SelectedValue
Case "XLS"
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition", "attachment; filename="
& "Report.xls")
ef.SaveXls(Response.OutputStream)
Exit Select
Case "XLSX"
Response.ContentType = "application/vnd.openxmlformats"
Response.AddHeader("Content-Disposition", "attachment; filename="
& "Report.xlsx")
Dim ms As New MemoryStream()
ef.SaveXlsx(ms)
ms.WriteTo(Response.OutputStream)
Exit Select
End Select
Response.End()
|
|
|
|
 |
|
 |
Hi,
My requirement is to export Russian Data stored in Oracle 9i Database to a CSV file.
When the below code is used to export data the Russian Characters are shown as Junk characters when the CSV file is opened in MSExcel. If the same file is opened in Notepad, the Russian Characters are displayed correctly.
Can you advice, how to export Russian Characters that can also be displayed correctly when viewed in Excel Sheet.
It will be highly appreciated.
With Regards,
/////////////////////////////////////////////////////////////////////////////
/////////////////////// PROGRAM CODE ////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
String strFileName = "";
FileStream fs = null;
BufferedStream buff = null;
StreamWriter writer = null;
bool bExported = false;
try
{
SaveFileDialog saveFileDlg = new SaveFileDialog();
saveFileDlg.Filter = "CSV Format|*.csv";
saveFileDlg.Title = "Save File";
saveFileDlg.RestoreDirectory = true ;
saveFileDlg.ShowDialog();
if(saveFileDlg.FileName != "")
{
strFileName = saveFileDlg.FileName;
saveFileDlg.Dispose();
fs = new FileStream
(strFileName,FileMode.OpenOrCreate,FileAccess.ReadWrite);
buff = new BufferedStream(fs);
writer = new StreamWriter(buff);
writer.Write(strWriteData);
writer.Flush();
bExported = true;
writer.Close();
buff.Close();
fs.Close();
}
return bExported;
}
catch(Exception exp)
{
throw exp;
}
finally
{
writer = null;
buff = null;
fs = null;
}
|
|
|
|
 |
|
 |
I think you are saving it in ANSI Encoding, try to save it in UNICODE Encoding.
It should solve your purpose.
Best Regards,
VS
|
|
|
|
 |
|
 |
Hi,
If you are using .NET DataSet class to hold your data in app memory then you could export it to CSV with GemBox.Spreadsheet .NET Excel component.
GemBox.Spreadsheet supports International characters (Unicode support) so you could check it out.
|
|
|
|
 |