This is a migrated thread and some comments may be shown as answers.

Telerik.Web.Spreadsheet removing zeros from string when saving

2 Answers 167 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 05 Jan 2017, 12:06 AM

Hello, I am struggling with a minor annoying issue when trying to save a worksheet.  Basically, I am placing string values into cells that start with 0 ex: "012345".  I then try to save the workbook to a local directory and the zero is being removed.  I understand this behavior being desired for numeric values but I am specifically formatting this cell as text, in which case I expect the string value to be saved exactly as it is written.  Am I missing something? Do I need to format the columns?  I have attached the resulting file as well as a screenshot showing values in watch window just prior to save.  Here is a sample of my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Web.Spreadsheet;

namespace KendoSpreadsheetPaddedZeroIssue.Controllers
{
    public class SpreadsheetController : Controller
    {
        public ActionResult SaveSpreadsheet()
        {
            Workbook resultWorkBook = new Workbook();
            resultWorkBook.AddSheet();
            Worksheet resultWorkSheet = resultWorkBook.Sheets[0];
            resultWorkSheet.ShowGridLines = true;
            resultWorkSheet.Name = "test1";
            resultWorkBook.ActiveSheet = "test1";
            

            List < Cell > cellItems = new List<Cell>();

            cellItems.Add(new Cell() {Index = 0, Format = "@", Value = "01234", Bold = false, FontSize = 13, TextAlign = "center", VerticalAlign = "center" });
            cellItems.Add(new Cell() {Index = 1, Format = "@", Value = "05678", Bold = false, FontSize = 13, TextAlign = "center", VerticalAlign = "center" });
            Row testRow = new Row() { Index = 0, Height = 20, Cells = cellItems };
            Worksheet testWorkSheet = resultWorkBook.Sheets[0];
            testWorkSheet.AddRow(testRow);

            resultWorkBook.Save(@"somepathonmydesktop\Test.xlsx");

            return View("Index");
        }

    }

}

2 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 06 Jan 2017, 04:28 PM
Hello James,

I was able to replicate the described issue at my end. Indeed, using the server-side export and the specified format does not export the excel file with the correct value, while using the client-side export and "@" format for the cell (where its value is e.g. 01234) the exported excel contains the correct value.  We are currently investigating the issue further and will let you know once we have further information on the matter.

Thank you in advance for your patience.


Regards,
Nencho
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Accepted
Nencho
Telerik team
answered on 10 Jan 2017, 09:21 AM
Hello,

I am afraid that after further inspection, the problematic behavior turned out to be a bug in the Save method and more specifically in setting the values in the exported excel document.

The logged issue on the matter could be found below:

https://github.com/telerik/kendo-ui-core/issues/2598


Regards,
Nencho
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Spreadsheet
Asked by
James
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Share this question
or