How to Format Cells in Template

HI

am using WorkbookDesigner to fill excel.Now i need to know how to format a cell in the template like Percentage,so that percentage sysmbol should come in the cell values Like 45%

Regards

Ajeesh

Hi,


Well, you can format the relevant smart markers in the cells in the template Excel file (in MS Excel) manually, e.g

Using Microsoft Excel, you can right click on any desired cell and select Format Cells… option then a dialog appears that allows to set the display formats of any kind of value as shown below

In the left side of the above figure, you can see that there are many categories of the values like General, Number, Currency, Accounting, Date, Time, Percentage etc. Aspose.Cells supports all of these categories to set the display format of numbers or dates.



Thank you.



Hi

Here by am attaching my Template Excel file and the Result Excel file.In template excel file i have a field called EmpiD and i made it format as Percentage in manually,But its not comming in result.

DataTable dt = new DataTable();

DataRow dr;

dt.Columns.Add("EmpId");

dt.Columns.Add("EmpName");

dr = dt.NewRow();

dr["EmpId"]="1";

dr["EmpName"] = "Test1";

dt.Rows.Add(dr);

dr = dt.NewRow();

dr["EmpId"] = "2";

dr["EmpName"] = "Test2";

dt.Rows.Add(dr);

dt.TableName = "Test";

WorkbookDesigner wd = new WorkbookDesigner();wd.Workbook = new Workbook(@"C:\Documents and Settings\amj001\Desktop\Test.xlsx");

wd.SetDataSource(dt);

wd.Process(true);

wd.Workbook.Save(@"C:\Documents and Settings\amj001\Desktop\Result.xlsx"); this is my code can u check my template as well as code

Regards

Ajeesh

Hi,


The reason that it is not working because your data in EmpID filed is text/string, please input numeric data as percentage format would only be worked on numeric data or numbers.

e.g

DataTable dt = new DataTable();

DataRow dr;

dt.Columns.Add(“EmpId”, typeof(int));

dt.Columns.Add(“EmpName”);

dr = dt.NewRow();

dr[“EmpId”]=1;

dr[“EmpName”] = “Test1”;

dt.Rows.Add(dr);

dr = dt.NewRow();

dr[“EmpId”] = 2;

dr[“EmpName”] = “Test2”;

dt.Rows.Add(dr);

dt.TableName = “Test”;

WorkbookDesigner wd = new WorkbookDesigner();wd.Workbook = new Workbook(@“C:\Documents and Settings\amj001\Desktop\Test.xlsx”);

wd.SetDataSource(dt);

wd.Process(true);

wd.Workbook.Save(@“C:\Documents and Settings\amj001\Desktop\Result.xlsx”);

HI

Thanks for your replay.The above code is working too.Now the problem is instead of 1% its displaying 100%.How to over come this

Hi,


This is how MS Excel works. For confirmation, open Ms Excel and a new Workbook, now enter “1” into a cell, when you format right clicking on it by using Format Cells… dialog, now click “Percentage” in the left list, you will see 100.00%. You need to enter “0.01” instead. i.e. 1/100 = 0.0.1

Also check the thread posts:
Percentage value
Percentage value

Thanks for your understanding!