Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 22nd, 2005, 02:17 AM
Registered User
 
Join Date: Nov 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Export to Excell - Bracketed Values Problem

Hi
I am trying to export my datagrid values to my excell sheet. All are fine except one thing. Some values are enclosed with round brackets like (3.2) in my database as well as in my datagrid. But when I export it to excell it replaces round brackets with the negative sign. I use the following code to initialize the property to set it as in round bracket. But I don't know somehow it is not working. The code is....
public void datagridToExcell(DataGrid dgExport,HttpResponse response)
    {
            response.Clear();
            response.Buffer = true;
            response.Charset = "";
            response.Cache.SetCacheability(HttpCacheability.No Cache);
            response.ContentType = "application/vnd.ms-excel";
            this.EnableViewState = false;
            response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
            response.Write("\r\n");
            response.Write(@"<style>.NumberString {mso-number-format:\@;}</style>");
            StringWriter objStrWriter = new StringWriter();
            HtmlTextWriter objHTMLTextWriter = new HtmlTextWriter(objStrWriter);
            DataGrid dg = new DataGrid();
            dg = dgExport ;
            dg.GridLines = GridLines.None;
            dg.HeaderStyle.Font.Bold = true;
            dg.DataBind();
            for (int rowPos = 0; rowPos < dg.Items.Count; rowPos++)
            {
                for (int colPos = 0; colPos < dg.Items[rowPos].Cells.Count; colPos++)
                {
                    dg.Items[rowPos].Cells[colPos].Attributes.Add("class","NumberString");
                }
            }
            dg.RenderControl(objHTMLTextWriter);
            response.Write(objStrWriter.ToString());
        }
If possible please any one help me. I am using Visual Studio .NET 1.1 and Microsoft Office 2003. I want to set the bracketed figuers with the bracket in red color. Yor can see this property in excel. Just go to the format option in the cell and then the number option.
Thanks in advance.....

Arindam Jha
 
Old November 22nd, 2005, 08:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Thats happening because values withing parantheses, by conventions, are taken as negative for accounting calculations etc. Set the NumberFormat property of the said cell to "#,##0.00_);[Red](#,##0.00)" from your program code. This format string will leave the positive numbers alone but turn the negative numbers red. Change the padding or formating as you please.

Regards
Ankur Verma





Similar Threads
Thread Thread Starter Forum Replies Last Post
Export Values to Excel Sheet from Sub form ayazhoda Access VBA 3 June 12th, 2012 03:18 PM
Export problem Kevin Barrett Crystal Reports 0 August 23rd, 2006 10:24 AM
ADO Problem fro extracting excell data mmmhbd ADO.NET 1 May 20th, 2006 02:50 AM
Export data to several excell sheets at will milocold Crystal Reports 0 November 16th, 2005 11:42 AM
Export DatSet to Excell format thomaz C# 2 September 16th, 2005 08:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.