|
Hi all,
I having a datatable and i want to export it to word format.In that format i want to define header footer and other type of formatting.
so can any one tell me how to do it.
Thanks in advance.
|
|
|
|
|
assign the datatable in a gridview then give a button as "Export to Word"
//double click the button and write this code
protected void btnword_Click(object sender, EventArgs e)
{
Response.AddHeader("content-disposition", "attachment;filename=Information.doc");
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);
// Create a form to contain the grid
HtmlForm frm = new HtmlForm();
GridView1.Parent.Controls.Add(frm);
frm.Attributes["runat"] = "server";
frm.Controls.Add(GridView1);
frm.RenderControl(htmlWrite);
//GridView1.RenderControl(htw);
Response.Write(stringWrite.ToString());
Response.End();
}
Padmanabhan
|
|
|
|
|
No without using gridview i want to do
|
|
|
|
|
u want to export the whole .aspx page to word am i correct.....
Padmanabhan
|
|
|
|
|
No i am having data in datatable with different number of fields.In word i want to display those fields with some different formats like adding the side heading and displaying the records which comes under it and so on...
|
|
|
|
|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class sss : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private DataTable GenerateDataTable()
{
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(String));
dt.Columns.Add("Email", typeof(String));
dt.Columns.Add("Gender", typeof(String));
dt.Columns.Add("Salary", typeof(int));
dt.Columns.Add("Image", typeof(String));
DataRow dr = dt.NewRow();
dr["Id"] = 1;
dr["Name"] = "Padmanabhan";
dr["Email"] = "mail2padmanabhan@gmail.com";
dr["Gender"] = "Male";
dr["Salary"] = 10000;
dr["Image"] = "232.jpg";
dt.Rows.Add(dr);
DataRow dr1 = dt.NewRow();
dr1["Id"] = 2;
dr1["Name"] = "Varatharaman";
dr1["Email"] = "varatharaman@gmail.com";
dr1["Gender"] = "Male";
dr1["Salary"] = 20000;
dr1["Image"] = "Photo-0009.jpg";
dt.Rows.Add(dr1);
DataRow dr2 = dt.NewRow();
dr2["Id"] = 3;
dr2["Name"] = "Sathya";
dr2["Email"] = "sathay@gmail.com";
dr2["Gender"] = "Male";
dr2["Salary"] = 10500;
dr2["Image"] = "DSC00010.JPG";
dt.Rows.Add(dr2);
return dt;
}
protected void Button1_Click(object sender, EventArgs e)
{
string fileName = System.Guid.NewGuid().ToString().Replace("-", "") + ".doc";
(new ExportDemo.Libraries.ExcelConvertor()).Convert(GenerateDataTable(), Server.MapPath("."), fileName);
Response.Redirect(fileName);
}
}
//you have to include a .cs file in App_code as WordConvertor.cs and paste this code
using System;
using System.Data;
using System.IO;
using System.Text;
namespace ExportDemo.Libraries
{
/// <summary>
/// To generate excel file.
/// </summary>
public class ExcelConvertor
{
/// <summary>
/// To generate excel file.
/// </summary>
/// <param name="oDataTable"></param>
/// <param name="directoryPath"></param>
/// <param name="fileName"></param>
/// <returns></returns>
public string Convert(DataTable oDataTable, string directoryPath, string fileName)
{
string fullpath = "";
if (directoryPath.Substring(directoryPath.Length - 1,1) == @"\" ||directoryPath.Substring(directoryPath.Length - 1,1) == "/")
{
fullpath = directoryPath + fileName;
}
else
{
fullpath = directoryPath + @"\" + fileName;
}
StreamWriter SW;
SW=File.CreateText(fullpath);
StringBuilder oStringBuilder = new StringBuilder();
/********************************************************
* Start, check for border width
* ******************************************************/
int borderWidth = 0;
if (_ShowExcelTableBorder)
{
borderWidth = 1;
}
/********************************************************
* End, Check for border width
* ******************************************************/
/********************************************************
* Start, Check for bold heading
* ******************************************************/
string boldTagStart = "";
string boldTagEnd = "";
if (_ExcelHeaderBold)
{
boldTagStart = "<B>";
boldTagEnd = "</B>";
}
/********************************************************
* End,Check for bold heading
* ******************************************************/
oStringBuilder.Append("<Table border=" + borderWidth + ">");
/*******************************************************************
* Start, Creating table header
* *****************************************************************/
oStringBuilder.Append("<TR>");
foreach(DataColumn oDataColumn in oDataTable.Columns)
{
oStringBuilder.Append("<TD>" + boldTagStart + oDataColumn.ColumnName + boldTagEnd + "</TD>");
}
oStringBuilder.Append("</TR>");
/*******************************************************************
* End, Creating table header
* *****************************************************************/
/*******************************************************************
* Start, Creating rows
* *****************************************************************/
foreach(DataRow oDataRow in oDataTable.Rows)
{
oStringBuilder.Append("<TR>");
foreach(DataColumn oDataColumn in oDataTable.Columns)
{
if (oDataRow[oDataColumn.ColumnName] is long)
{
oStringBuilder.Append("<TD align=right>" + oDataRow[oDataColumn.ColumnName] + "</TD>");
}
else
{
oStringBuilder.Append("<TD>" + oDataRow[oDataColumn.ColumnName] + "</TD>");
}
}
oStringBuilder.Append("</TR>");
}
/*******************************************************************
* End, Creating rows
* *****************************************************************/
oStringBuilder.Append("</Table>");
SW.WriteLine(oStringBuilder.ToString());
SW.Close();
return fullpath;
}
private bool _ShowExcelTableBorder = false;
/// <summary>
/// To show or hide the excel table border
/// </summary>
public bool ShowExcelTableBorder
{
get
{
return _ShowExcelTableBorder;
}
set
{
_ShowExcelTableBorder = value;
}
}
private bool _ExcelHeaderBold = true;
/// <summary>
/// To make header bold or normal
/// </summary>
public bool ExcelHeaderBold
{
get
{
return _ExcelHeaderBold;
}
set
{
ExcelHeaderBold = value;
}
}
}
}
Padmanabhan
|
|
|
|
|
Hi All.,
I am new to URL rewriting.I am Using IHTTP Handlers to made URL Rewriting.After Rewriting My URL is Looks like as follows Http://localhost/ballistic/Ecards
for the Redirecting page the StyleSheets,Images and .ja file not applying.
This is very urgent for me..pls help on this
|
|
|
|
|
Member 3264122 wrote: This is very urgent for me
Not for me
Member 3264122 wrote: StyleSheets,Images and .ja file not applying
The reference to these resources is not valid anymore after the rewritting.
You should add the reference again during the runtime according tto the structure of your new url.
You can have a look here [^]to see how to add during reference runtime.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
hi.,
Thks for your kind reply.,
Where i have to add the Funtion in my application
|
|
|
|
|
How did you refer your images and script files in your asp.net pages. If the images are in the folder 'Images' and if your refered an image like
Make sure you root qualify CSS, Image and script references.
You have to qualify an image like "/image/yourimage.gif" instead of "image/yourimage.gif".
|
|
|
|
|
Hi.,
Thks for your kind reply.,
All the images and StyleSheet links are as you said.
|
|
|
|
|
Hi there,
I use the following codesnipet to retrieve the user information:
MembershipUser user = Membership.GetUser("username");
but I get this error:
Specified cast is not valid.
any idea?
|
|
|
|
|
This error might occur if your aspnet_ tables have some invalid records or if you edit the aspnet tables directly without using tools like ASP.NET confuguration tool.
Delete the asp_net tables and recreate them.
Hope this will help you.
|
|
|
|
|
MembershipUser user = Membership.GetUser("username");
in this the getuser is a method i think
so u have to cast like the below code
//CheckBox chkBxSelect = (CheckBox)e.Row.Cells[1].FindControl("chkselect");
Padmanabhan
|
|
|
|
|
how to get history of view pages in web application in asp.net ?///////
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
Eventure Technology
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
could you be more specific?
Do you want log each page that has been run by a user of you websystem?
In Word you can only store 2 bytes. That is why I use Writer.
|
|
|
|
|
Hi Team,
I have to create a table which should track the log information of all the tables in a database. when ever a row adds on the table1 then the new table should automatically add a row with the below information like 1.Table Name 2.Filed Name 3.oldvalue 4. new value 5.Created Date 6. Username
Kindly Suggest me
Thanks
|
|
|
|
|
Write a trigger on the table which will insert the details into your audit table.
|
|
|
|
|
i have created a window application for scanning,it work properly.
but we change it in web ,how we will do it,
plz give me proper process for it.
thanks & regards
vivek sachan
|
|
|
|
|
I think you already posted this question and you were answered that this can be done using some third parted ActiveX controls.
But this will work in IE only.
Have look on the following links:
Link1[^]
Link2[^]
|
|
|
|
|
Also look into the link[^]
|
|
|
|
|
To implement scanning functionality, you have to use ActiveX control and embeed it inside your page as an object. If you are asking for a proper process to convert a windows application into web application then I would rather suggest you to read some good books. I am afraid that it would not be possible to demonstrate the proper and exact process as nodbody knows the existing project and the requirement except you.
All the best.
Regards
Saanj
Either you love IT or leave IT...
|
|
|
|
|
Hi,
I am new web programming , so experts please excuse, I've created a simple web app in asp.net2.0 and sql server2000 .I wish to host this web site, and i payed for the webhosting provider. They send me the credentials like:
1. Host Usr name & passwd
2.Database details(ip address,name,usrname,pwd)
But my problem is , that i dont know how to copy my database scheme and data into the providers remote database server.i.e from a local db to remote db.
Plz help out !!!!!
Thax in Advance ...
|
|
|
|
|
Register the remote SQL server in your local SQl Server 2000 enterprise manager.
Then open your remote database and use DTS export/import wizard to copy data from your local database to remote database.
|
|
|
|
|
Thanks a lot for the replies !!!
But could guide me through the steps to register remote SQL server
Plz help!!
|
|
|
|