Hi,
I don't no VB.net, i send C# code for you please convert this into Whatever you want. Try the following code
<table class="TextVerdanaNavy8" width="75%" align="center">
<tr valign="top">
<td align="center" colspan="3">
<asp:label id="Label1" runat="server" text="Drawing Schedule" cssclass="PageHead" xmlns:asp="#unknown"></asp:label>
</td>
</tr>
<tr>
<td align="right">
Excel File :
</td>
<td align="left">
<asp:fileupload id="FileUpload1" width="50%" runat="server" xmlns:asp="#unknown" />
<asp:label id="lblmsg" runat="server" text="" xmlns:asp="#unknown"></asp:label>
<asp:button id="btnGetExcelSheetList" runat="server" onclick="btnGetExcelSheetList_Click" xmlns:asp="#unknown">
Text="Get Excel Sheet List" />
<br />
</asp:button></td>
</tr>
<tr>
<td align="right" valign="top" colspan="" class="style1">
<asp:label id="lblsheet" runat="server" text="Sheet Name : " xmlns:asp="#unknown"></asp:label>
</td>
<td valign="top" colspan="" class="style6">
<asp:dropdownlist id="ddlSheet" runat="server" autopostback="True" visible="False" xmlns:asp="#unknown">
SkinID="DropDownListSkin"
OnSelectedIndexChanged="ddlSheet_SelectedIndexChanged">
</asp:dropdownlist>
<br />
<br />
</td>
</tr>
<tr>
<td align="center" colspan="2">
<table>
<tr>
<td align="right">
<asp:linkbutton id="btnShow" runat="server" onclick="btnShow_Click" visible="false" xmlns:asp="#unknown">
Show Data
</asp:linkbutton>
</td>
</tr>
</table>
</td>
</tr>
</table>
private void Get_Sheets()
{
OleDbConnection oconn = null;
DataTable dt = null;
try
{
string FilePath = string.Empty;
string FileName = string.Empty;
if (FileUpload1.HasFile)
{
FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
string Extension = Path.GetExtension(FileUpload1.PostedFile.FileName);
string FolderPath = ConfigurationManager.AppSettings["PRPOFolder"];
FilePath = Server.MapPath(FolderPath + FileName);
ViewState["FilePath"] = FilePath;
ViewState["FileName"] = FileName;
FileUpload1.SaveAs(FilePath);
}
oconn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FilePath + ";Extended Properties=Excel 8.0");
oconn.Open();
dt = null;
dt = oconn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (dt == null)
{
}
String[] sheet = new String[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
sheet[i] = dr["TABLE_NAME"].ToString();
i++;
}
string[] a = sheet;
int j = 0;
if (a != null && a.Length > 0)
{
ddlSheet.Visible = true;
lblsheet.Visible = true;
for (j = 0; j < a.Length; j++)
{
ddlSheet.Items.Add(a[j]);
}
ddlSheet.Items.Insert(0, "<--- Select Excel Sheet --->");
}
else
{
ddlSheet.Visible = false;
lblsheet.Visible = false;
}
}
catch (Exception ex)
{
}
finally
{
if (oconn != null)
{
oconn.Close();
oconn.Dispose();
}
if (dt != null)
{
dt.Dispose();
}
}
}
protected void btnGetExcelSheetList_Click(object sender, EventArgs e)
{
ddlSheet.Items.Clear();
Get_Sheets();
}
protected void btnShow_Click(object sender, EventArgs e)
{
gdDrawing.Visible = false;
Display();
}
private void Display()
{
OleDbConnection oconn = null;
DataTable dt1 = new DataTable();
try
{
string FileName = ViewState["FileName"] as string;
string FilePath = ViewState["FilePath"] as string;
oconn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FilePath + ";Extended Properties=Excel 8.0");
OleDbCommand ocmd = new OleDbCommand("select * from [" + ddlSheet.SelectedItem.ToString() + "]", oconn);
oconn.Open();
OleDbDataReader odr = ocmd.ExecuteReader();
DesignService.Design ODesign = new DesignService.Design();
string Title = string.Empty;
string Size = string.Empty;
dt1.TableName = FileName;
dt1.Columns.Add("Title");
dt1.Columns.Add("Size");
while (odr.Read())
{
Title = odr["Title"].ToString();
Size = odr["Size"].ToString();
DataRow dr = dt1.NewRow();
dr["Title"] = Title;
dr["Size"] = Size;
dt1.Rows.Add(dr);
}
if (dt1.Rows.Count > 0)
{
btninsert.Visible = true;
Session["Table"] = dt1;
gvExcelData.Visible = true;
gvExcelData.DataSource = dt1;
gvExcelData.DataBind();
}
else
{
btninsert.Visible = false;
}
}
catch (DataException ex)
{
}
finally
{
if (oconn != null)
{
oconn.Close();
oconn.Dispose();
}
if (dt1 != null)
{
dt1.Dispose();
}
}
}
upto here data will be displayed in GridView , now you export gridview data to pdf
refer this link for exporting gridview to pdf
http://forums.asp.net/p/1425195/3174526.aspx[
^]
I think this might be helpfull to you...