0 Replies - 2837 Views - Last Post: 01 August 2012 - 06:56 PM Rate Topic: -----

#1 khaos24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 06-June 11

Exporting To Excel Issues

Posted 01 August 2012 - 06:56 PM

Hey Everyone!

I'm using Spreadsheet Gear in my .NET C# application to capture the dataset into an excel worksheet. The worksheet is getting populated just fine but I am having issues with the format of the currency. For instance, in the database the value is 3.19 but it populates in the Excel worksheet as 31,900.00 The currency I am trying to display in the Worksheet is the Euro so ideally it should display as €3,19 instead of €31,900.00

I don't know how to go about this because it isn't throwing an error out. I was thinking if there was a way to divide the values of the dataset by 10,000 but I am not sure if that will solve the issue.

Here is my code:
 protected void Excel_Click(object sender, EventArgs e)
    {

        Response.ContentType = "application/vnd.ms-excel";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("iso-8859-1");
        string filename = "Summary" + Session["Subst"].ToString() + ".xls";
        Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);

        IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook(Server.MapPath("Images/Excel.xls"));
        IWorksheet ws = workbook.Worksheets[0];

        int store = (int)Session["Subst"];
        DataSet ds = DataAccess.GetExcel(store);

        string search;
        IRange cell;
        search = "%%Anchor";
        cell = ws.Cells.Find(search, null, FindLookIn.Values, LookAt.Whole, SearchOrder.ByColumns, SearchDirection.Next, false);
        int columns = Convert.ToInt32(ds.Tables[0].Columns.Count);



        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
            {
                if (cell != null)
                {       
                    cell.Value = ds.Tables[0].Rows[i][j].ToString();
                    cell = cell.Offset(0, 1);

                }

            }
            cell = cell.Offset(1, -columns);
        }


        workbook.SaveToStream(Response.OutputStream, SpreadsheetGear.FileFormat.XLS97);




Any help would be much appreciated.

Thanks

This post has been edited by khaos24: 01 August 2012 - 06:57 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1