How to format Fractions

Apr 12, 2013 at 2:15 AM
I would like a cell with:

+1/2 + 1/4

to be displayed as 3/4

Under excel formatting this fraction - up to three digits (312/943)

Any help would be great!!!!

Thanks!!!!!!
Apr 12, 2013 at 7:22 PM
=1/2+1/4
Apr 12, 2013 at 7:37 PM
that gets me 0.75 what I would like it 3/4
Apr 12, 2013 at 8:43 PM
Edited Apr 12, 2013 at 8:58 PM
With ClosedXML I think you would use:

mCurrWorkSheet.column(1).style.numberformat.format = "# ???/???"
(this would set the format of a whole column)

From what I've seen you can pretty much put any custom format you would use in excel here and it will work.

See the documentation section for a full example of using numberformat.format :
https://closedxml.codeplex.com/wikipage?title=Styles%20-%20NumberFormat&referringTitle=Documentation
Apr 13, 2013 at 6:52 PM
Try to use this function:


Public Function CalcFraction(ByVal eString As String) As String
Dim TestBook As New XLWorkbook
Dim testworksheet = TestBook.Worksheets.Add("test")
testworksheet.Cell("a1").Value = eString
testworksheet.Cell("a1").Style.NumberFormat.Format = "# ???/???"
TestBook.CalculateMode = XLCalculateMode.Auto
Return TestBook.Evaluate(TestBook.Worksheets.Worksheet("test").Cell("a1").GetFormattedString)
End Function

to be given - 1/2 + 1/4 and get 3/4

Thanks for all your help!!!