C# - Make Exported .XLS File Editable?

Mar 4, 2010

How to make exported .XLS file Editable Thid code makes .XLS File Read Only

:(
using System;
using System.Data;
using System.Configuration;
using System.IO;
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 class GridViewExportUtil
{
/// <param name="fileName"></param>
/// <param name="gv"></param>
public static void Export(string fileName, GridView gv)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader(
"content-disposition", string.Format("content-disposition", "attachment; filename={0}", fileName));
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Charset = System.Text.Encoding.Unicode.EncodingName;
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Unicode;
HttpContext.Current.Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
// Create a form to contain the grid
Table table = new Table();
// add the header row to the table
if (gv.HeaderRow != null)
{
GridViewExportUtil.PrepareControlForExport(gv.HeaderRow);
table.Rows.Add(gv.HeaderRow);
}
// add each of the data rows to the table
foreach (GridViewRow row in gv.Rows)
{
GridViewExportUtil.PrepareControlForExport(row);
table.Rows.Add(row);
}
// add the footer row to the table
if (gv.FooterRow != null)
{
GridViewExportUtil.PrepareControlForExport(gv.FooterRow);
table.Rows.Add(gv.FooterRow);
}
// render the table into the htmlwriter
table.RenderControl(htw);
// render the htmlwriter into the response
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
}
}
}
/// <summary>
/// Replace any of the contained controls with literals
/// </summary>
/// <param name="control"></param>
private static void PrepareControlForExport(Control control)
{
for (int i = 0; i < control.Controls.Count; i++)
{
Control current = control.Controls[i];
if (current is LinkButton)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as LinkButton).Text));
}
else if (current is ImageButton)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as ImageButton).AlternateText));
}
else if (current is HyperLink)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as HyperLink).Text));
}
else if (current is DropDownList)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as DropDownList).SelectedItem.Text));
}
else if (current is CheckBox)
{
control.Controls.Remove(current);
control.Controls.AddAt(i, new LiteralControl((current as CheckBox).Checked ? "True" : "False"));
}
if (current.HasControls())
{
GridViewExportUtil.PrepareControlForExport(current);
}
}
}
}

View 1 Replies


Similar Messages:

Mvc DataAnnotations How To Make Field No Editable In 3.5

May 20, 2010

I have a few field in my entity that i wish to be non-editable. Looking in the docs it seems like "EditableAttribute" would do the trick. However this is only 4.0Just wondering if there are other attributes that would have the desire effect. So be clear, i have a field called "DateRegistered" i wish to display this as string not text field using "Html.EditorFor"

View 2 Replies

Web Forms :: GridView - How To Make Editable Columns As Dropdownlistbox

Mar 24, 2011

I have an editable GridView and I would like to add dropdownlistbox for editable columns. Is there a way to do it? I want to bind the data also so the dropdownlistbox comes with values.

Here is a sample source code:

[Code]....

View 3 Replies

Forms Data Controls :: How To Make Editable Gridview

Feb 28, 2010

I want to make an editable gridview with 4 boundfield. When a row is selected, I want to edit the value of the 2 boundfield. Can I use edit, update commandfield?. Because when I tested it, all the columns of the selected row becomes editable.

View 4 Replies

How To Make A Readonly Text Box Editable On Mouse-over Using J Query

Aug 15, 2010

I have a read-only text-box with text in it. How to make it editable on mouse-over using J query ?

View 1 Replies

C# - Make A Specific Column Editable Upon Clicking Edit?

Jan 22, 2011

I have a gridview with "Edit Update Cancel" command field. When I click Edit, all the columns in the particular row becomes editable. I just need to have 2 specific columns editable. How is that made possible ? (Screen Shot Attached) [In the screen shot all 3 columns are editable, I just need the second and third to be editable]

View 2 Replies

Web Forms :: Rename Exported PDF File In RDLC Report Viewer

May 7, 2015

I have an issue in report viewer export Receipt into pdf. I am using your code and at time export the file name comes based on pagename. Like Receipt.pdf

If i want send receipt to my customer, i need to include the receipt number like TE724785872/201503-2. user always do wrong enter the receipt number to store in the folder to send the customer later.

It is also very diffcult find receipt on time of sending to customer. We have to open one by one and check and attached in email. 

Is there any possible reportveiwer add receipt number automatically on time of export into PDF

(like TE72478/201308-2.pdf)

View 1 Replies

Forms Data Controls :: Make A Gridview Editable Programmatically - Per Row

Nov 3, 2010

I have a gridview with bound fields and a templateField that receives data from a submit button which, depending upon the selected object, i.e. dropdown 1, 2, or 3, return a result set. The gridview also has a checkbox column which is used as a marker to determinie the rows to be added to and existing table. If a user selects multiple row, those rows are written to the database. Everything works.

Now, I need to add additional functionality to the gridview:

Upon selecting the checkbox, programmatically the accompanying row must become editable; for each row presented.

Deselected the checkbox, return the gridview row to a read-only state.

There are 14 columns, one of which is a dropdown which needs to maintain its default value.

View 1 Replies

Forms Data Controls :: Make Editable Grid View

Sep 21, 2010

i have created an application which shows records from the database i have to make my grid view editable so that it will reflect into the data base

View 17 Replies

Forms Data Controls :: Make Gridview Row Editable On Redirect

Jan 7, 2011

I have two pages; one page similar to a 'dashboard' displaying an incoming correspondence gridview and the other page 'incoming' displaying the same gridview of incoming correspondence. So my dashboard page is just a snap shot of what some pages have. So there are main pages that are being summarized in the dashboard. What I want to do with the Incoming gridview in the 'Dashboard' Page is once a user clicks a row in that gridview it obtains the correspondence id and redirects to the Incoming page and make that row in that gridview(same view or query as the gridview in the dashboard) editable.

What I have right now is I am obtaining the correspondence id for the row selected and redirecting to the Incoming page but have noo idea how to make that row editable in the gridview in the Incoming page.

View 5 Replies

JQuery :: Make All Columns Editable At Same Time Of A Row Via Jeditable Plugin?

Dec 7, 2010

i am working with jeditable plugin in MVC ,what I'm trying to do is click a button and all the fields a certain row become editable and automatically go to their editable state.. so, in other words, I have a table, I want to click Edit on the side of a row and all the columns in that row become editable .

View 1 Replies

How To Make GridView Column Read Only / Editing Whole Row Of The Grid Is In Editable Mode?

Jun 2, 2010

I am using Gridview and on that data is binded conditionally.the problem is that at the time of editing whole row of the grid is in editable mode and i want only few of the columns editable. my code is as follows

[code]....

View 4 Replies

Forms Data Controls :: Make Editable Gridview - Add - Update - Delete

Feb 24, 2010

I've got my data in the gridview via:

[Code]....

Now I need to make all the data editable (add, update, delete). Why isn't the Gridview the same as DataGridView? With the DGV, the data showed EXACTLY as it did in the database and one could add a record, edit a record, or delete a record.

View 2 Replies

Forms Data Controls :: Binding A Gridview From Session - Make Editable

May 31, 2010

In my project i am binding a gridview from session and i want to make it editable. i handled the rowediting,rowupdating and cancelediting event as suppose to and at run time i bound my data to the grid cells in the rowdatebound like this

if (e.Row.RowType == DataControlRowType.DataRow)
{ RequiredPaper paper = (RequiredPaper)e.Row.DataItem;
e.Row.Cells[0].Text = paper.PaperDesc;
}

and every time i click on the edit link in the grid view the cell never turns in the edit mode so i can not edit it!

View 4 Replies

Forms Data Controls :: Gridview - Make All The Row Editable When User Click This Button

Aug 25, 2010

I am working in a asp.net page, Where I have a button "Edit Grid". I would like to make all the row editable when user click this button.

View 4 Replies

Forms Data Controls :: Make Gridviews And Labels Into Non - Editable Single Report

Jan 24, 2011

I have 3 gridview,4 lables having the information, i have a button(Report), when i click this i want make this as Non-editable format single report. i have seen converting Webform to PDF but we should fall back to 3rd party tool to produce the report.

View 4 Replies

Forms Data Controls :: How To Make Number Of Editable Columns Of Gridview Depends On A Textbox Value

Oct 4, 2010

I have a Gridview with 12 columns, Jan, Feb...Dec.

I have a textbox value that could be 1, 2,...12

I want if textbox value is 7, then column Aug-Dec in Gridview is editable when in update mode and the column in Jan-Jul is not updatable (eg make it label instead of textbox).

How can I do this ?

View 3 Replies

Forms Data Controls :: Make Gridview Rows Editable On The Click Event Of A Button

Sep 20, 2010

How to make gridview rows editable on the clilck event of a button.

View 3 Replies

Forms Data Controls :: Editable Gridviews - Updating Rows Not Editable / Bound

Jun 30, 2010

Note: Code is taken from this tutorial [URL] I currently have an editable gridview with only some columns editable by the user. In the background I want to record the time/date they have saved the data to the grid. This column 'Time' is not bound to the grid. Is there anyway I can still include this update when rebinding the newly edited data?

I'm also having a problem saving the updated data of my column ActivityTotal. I've been debugging that and following the variable, and it holds the correct value, but just doesnt seem to update. I am providing the codes below for both my gridview and the cs behind and would be grateful if someone could take a look, I assume it's a sort of minor sql issue on my part.

code

protected void UpdateButton_Click(object sender, EventArgs e) { originalDataTable = (DataTable)ViewState["originalValuesDataTable"]; foreach (GridViewRow r in GridView_ABC.Rows) if (IsRowModified(r)) { GridView_ABC.UpdateRow(r.RowIndex, false); } // Rebind the Grid to repopulate the original values table. tableCopied = false; GridView_ABC.DataBind(); }

View 4 Replies

AJAX ::possible To Make An DIV "editable"?

Jan 21, 2010

i several DIV's where the user should be able to insert html content via an editor.I want to enable the user to "click" inside the div and then it should be converted into an "Editor" (e.g.
http://cutesoft.net/asp/EnableAll.asp).

1. The Site opens

2. The editable areas are marked with an different background color

3. The user should click in this area

4. the area turns into an editor and a save button

5. on click the save button the content should be saved and the DIV content refreshed is this possible with AJAX and for what should i look for?

View 5 Replies

Data Controls :: Export GridView To Non Editable (Locked) Excel File

Aug 12, 2013

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Me.IsPostBack Then Dim dataSet1 As New DataSet dataSet1 
Dim dataSet2 As New DataSet dataSet2  Dim dataSet3 As New DataSet dataSet3

Dim dataSets As New List(Of DataSet)() dataSets.Add(dataSet1) dataSets.Add(dataSet2) dataSets.Add(dataSet3)
Dim strout As String = Server.MapPath("test1.xls") DataSetsToExcel(dataSets, strout) End If End Sub

[Code]..

How to create each excel sheet non-editable (read only)

View 1 Replies

Configuration :: Importing An Exported Site From IIS

Mar 5, 2011

I've taken over the development of a website for a friend of mine. The original site manager used SiteFinity CMS, and hosted at winhost.com. I'm not changing this, but I wanted to create a local VS2010 project of the site that currently is hosted at winhost.com. How do I go about this? I have exported the site to a ZIP file through the IIS manager, but now my problem is getting that site into VS2010 blank C# Web project successfully. I've primarily worked with Dreamweaver to do site management before this is my first VS2010 site.

View 1 Replies

Web Forms :: Width Of Exported PDF Document?

Nov 2, 2013

How can I change the width of the exported gridview to pdf  document

I followed your method, my gridview has 9 columns the width of the document is not expanded.

View 1 Replies

Web Forms :: Do Calculation In Exported Excel Using C#

Nov 25, 2012

I am exporting only two columns to the excel

"Amount" and "Out Of 10 Percent".

I will enter the amount in "Amount" column and "Out Of 10 Percent", i will display the 10 Percent of the amount

Say            Amount        Out Of 10 Percent

                 1000                100

                 100                   10.

I can do the calculation in C# and i can able to export the content to excel as above.

My need is in the exported excel, if change the amount means i should able to get the corresponding amount in the next column.

(i.e) in the exported excel, if i edit the "Amount" ->1000 to 500 means the next column "Out Of 10 Percent" should change as 100 -> 50. I mean it should be auto calculated in the exported excel.

View 1 Replies

.net - Add Title Row To RadGrid Exported Excel Sheet?

Aug 18, 2010

I would like to add a Title row to an exported File from a Rad Grid. How can I do this?

<telerik:RadGrid ID="RadGridHist" runat="server" DataSourceID="SqlDataSourceHist" Visible="false"
AutoGenerateColumns="false" AllowPaging="true" AllowSorting="true" OnPageIndexChanged="RadGridHist_PageIndexChanged"
OnPageSizeChanged="RadGridHist_PageSizeChanged" OnItemCommand="RadGridHist_ItemCommand" OnSortCommand="RadGridHist_SortCommand"

[Code].....

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved