|
Hi,
I wanna create an Excel file cell by cell with formating in asp.net.
I have data in dataset or in HTML file.Now is there any way through which i could transfer the data in HTML in same format in excel.
If i have to do it through Dataset to Excel then i need a method through which i could access each cell of excel.Else i need a method through which entire HTML can be transfered in Excel with all its format.
Can any1 have the solution....Thnx...
|
|
|
|
|
There are a few ways that you can go about this, depending on how complex your spreadsheet and formatting needs are. In a simple case, the approach that you mention of forming HTML and tricking Excel into parsing it, is a good one. There are plenty of articles available if you care to google, but the basic implementation involves you setting header values from your page. For example:
Response.AddHeader("content-disposition", "attachment; filename=MyExcelSheet.xls"); Response.ContentType = "application/ms-excel";
That technique only works if the formatting is simple. If you require more advanced formatting or the use of formulas, you may wish to consider purchasing one of the commercial components that allow you to work with the Excel native format without Office being present on the machine, such as this[^] one.
As a last resort, it is possible to install Office on the server and use the Office interop assemblies to automate Excel. Please note that I label this the last resort, because it is slower, consumes more resources, and requires client software to be installed on a server (potentially increasing the attack surface.)
Hope that helps.
--Jesse
"... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi
|
|
|
|
|
Thnx for your reply....
i got this article from net but still not even able to create an object of application...i have included ref of excel object too...dont knw why Application object in first line now created...
code is as follows:-
In this article, we are going to see how to open a write a dataset to a excel file and open the excel file in the browser.
In order for this to work, there is an important modification in web.config file. We have to add <identity impersonate="true"> else you will get an 'Access is denied' error.
In the application, we have to add a reference for a COM component called "Microsoft Excel 9.0 object library".
Now we have to just loop through the dataset records and populate to each cell in the excel.
Code:
private void createDataInExcel(DataSet ds)
{
Application oXL;
_Workbook oWB;
_Worksheet oSheet;
Range oRng;
string strCurrentDir = Server.MapPath(".") + "\\reports\\";
try
{
oXL = new Application();
oXL.Visible = false;
//Get a new workbook.
oWB = (_Workbook)(oXL.Workbooks.Add( Missing.Value ));
oSheet = (_Worksheet)oWB.ActiveSheet;
//System.Data.DataTable dtGridData=ds.Tables[0];
int iRow =2;
if(ds.Tables[0].Rows.Count>0)
{
// for(int j=0;j
|
|
|
|
|
What you're attempting to do in that code is to use COM interop to automate the Excel client. You are most likely failing because Excel is not installed on your web server. As I mention in my original reply, I'd strongly recommend that you use this approach only as a last resort.
Please refer to my original reply for some alternatives.
--Jesse
"... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi
|
|
|
|
|
hi
i have a multiple selection listbox in the webform. i want to add the items of the listbox into a database, where in each item goes in a particular column.
i am implementing this using arrays. but wat i am not getting is how should i declare an array for the listbox.
i have declared an string type array with size 6, cuz i dont want more than 6 values to be selected.
finally, how shud i implemnt it...
string[] list = new string[5];
Kunal Piyush
|
|
|
|
|
I am clicking login button which is on home page.then login page comes up. After login that login button converted into logout on home page and at time if I clicked on the browser BACK button I get login page.But I am already logined, So I don't want that page when logout button is active on home page.
yog
hui gfgh kgdgrt njjn hjgkn
|
|
|
|
|
u will need to maintain sessions or cookies to obtain this functionality. this would add more security. also now if u logout and click a back button, you wont be redirected to the logged in home page.
Kunal Piyush
|
|
|
|
|
heay kunal....could u send some artiles relateing to this stuff
or the procedure to follow ...!
|
|
|
|
|
yuva..read the msdn documentation.. session states
there u will get exaustive info about the same.
Kunal Piyush
|
|
|
|
|
Thank you for reply.
I have used javascript
Window.history.go(+1)
in order to prevent user from going to the signin page .
Currently I'm not getting sign in page in all conditions whether user is logged in or not.
But I want this to happen only when user is already logged in .
I have maintained session for userid when user is logged in.
But don't understand how to restrict this code to execute only when user is logged in.
yog
hui gfgh kgdgrt njjn hjgkn
|
|
|
|
|
i dont know why u r using javascript.. this will go a page forward in the browsers history
wen u have already maintained a session id, add the code in the page_load event of the web form.
if (Session["user"] != null)
this means that if the user is logged in... add ur own code
hope it helps.
Kunal Piyush
|
|
|
|
|
I would like to find out if there is a way to set a conditional switch so that sections of code could be accessed depending on location. Something like C++ #ifdefine and #else switches. I have code that I am debugging, but I need to remove certian elements from the code while I debug, then when the code is ported to production, I don't want to have to readd the other code. Any ideas like something in the web.config that might allow me to do this simply. The hard way would be to make a global value then in the code use it in an if statement.
Leo T. Smith
|
|
|
|
|
I can't speak for Visual Basic (a quick search turned up nothing), but C# has built in
preprocessor directives[^], and also defines a flag called DEBUG when a solution is built in Visual Studio's debug configuration.
Just like in C++, you could write something similar to the following to force code to be present only in debug builds.
#if DEBUG // Insert code here #endif
Hope that helps.
--Jesse
"... the internet's just a big porn library with some useful articles stuck in." - Rob Rodi
|
|
|
|
|
Thanks, I didn't think this was available for some reason (probably kept using _DEBUG instead of DEBUG.
Leo
Leo T. Smith
|
|
|
|
|
I have a web application It works well in my local folder.. When i upload
> > it
> > to my web server i got
> >
> > To enable the details of this specific error message to be viewable on
> > remote machines, please create a <customerrors> tag within a "web.config"
> > configuration file located in the root directory of the current web
> > application. This <customerrors> tag should then have its "mode" attribute
> > set to "Off".
> >
> >
> >
> >
> > Server Error in '/' Application.
> > --------------------------------------------------------------------------------
> >
> > Runtime Error
> > Description: An application error occurred on the server. The current
> > custom error settings for this application prevent the details of the
> > application error from being viewed remotely (for security reasons). It
> > could, however, be viewed by browsers running on the local server machine.
> >
> > Details: To enable the details of this specific error message to be
> > viewable on remote machines, please create a <customerrors> tag within a
> > "web.config" configuration file located in the root directory of the
> > current web application. This <customerrors> tag should then have its
> > "mode" attribute set to "Off".
Any Solution?
|
|
|
|
|
Have you done what the error suggested you do?
|
|
|
|
|
Hi,
Have you used exception handling ? If not, then there is a chance that an Unhandeled exception occurs. This form of screen is just notifying that the error details will not be displayed on the remote machine since the custom error mode is on or remote only. Just change it to Off and you will be able to see what the exception actually is. Be cautious about the upper case 'O' in the "Off"
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
on button click if validation false i weant to show message box
how can i show??
|
|
|
|
|
You'll need to hook in to the client side - if using .NET 2.0, each button has an OnClientClick property - path this to a javascript function, and use alert() to show yer message
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
|
|
|
|
|
Hi,
You the ErrorSummary to display message box if validation fails.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
after uploading my file when i am trying to open a webpage error is coming like that.when uploading an application in remote server i want to change anything in web config file?it's working properly in local machine
Server Error in '/' Application.
--------------------------------------------------------------------------------
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.
Source Error:
Line 44: by Microsoft that offers a single logon and core profile services for member sites.
Line 45: -->
Line 46: <authentication mode="Forms">
Line 47:
Line 48:
|
|
|
|
|
hi
how to write javascript function in html part
and how to call it in codebehind in asp.net using c#
pls reply me.
thanku
gayatri
Gayatri
|
|
|
|
|
Why would you need to call a javascript function from a code-behind page?
|
|
|
|
|
wrote: how to write javascript function in html part
Start <script> tag and write your functions like this
<script language="javascript">
function Sample()
{
alert("Hi Javascript");
}
</script>
Put the above code on your head section.
wrote: and how to call it in codebehind in asp.net using c#
Each control will be having one property called attributes. Use
ControlName.Attributes.Add("OnClick","Sample();");
|
|
|
|
|
Javascript is scripting language run at client side it run first before going to server
Thanks and Regards
Sandeep
If you want something you never had,
do something you have never done!
|
|
|
|