Wednesday, 07 September 2011 05:39
Calculate With Formula
The sample demonstrates how to calculate formulas
using System; using System.IO; using System.Windows.Forms; using Spire.Xls; namespace DataCalculateWithFormulas { class Program { static void Main(string[] args) { using (Stream buffer = WriteFormulas()) { //load Workbook workbook = new Workbook(); workbook.LoadFromStream(buffer); //calculate formula Object b3 = workbook.CaculateFormulaValue("=Sheet1!$B$3"); Object c3 = workbook.CaculateFormulaValue("=Sheet1!$C$3"); String formula = "=Sheet1!$B$3 + Sheet1!$C$3"; Object value = workbook.CaculateFormulaValue(formula); String message = String.Format("Sheet1!$B$3 = {0}, Sheet1!$C$3 = {1}, {2} = {3}", b3, c3, formula.Substring(1), value); MessageBox.Show(message, "Calculate Formulas"); } } private static Stream WriteFormulas() { //Create Excel files Workbook workbook = new Workbook(); Worksheet sheet = workbook.Worksheets[0];//it's the first sheet of the worksheets int currentRow = 1; string currentFormula = string.Empty; sheet.SetColumnWidth(1, 32);//SetColumnWidth(columnIndex,width); sheet.SetColumnWidth(2, 16); sheet.SetColumnWidth(3, 16); sheet.Range[currentRow++, 1].Value = "Examples of formulas :"; sheet.Range[++currentRow, 1].Value = "Test data:"; CellRange range = sheet.Range["A1"]; range.Style.Font.IsBold = true; range.Style.FillPattern = ExcelPatternType.Solid; range.Style.KnownColor = ExcelColors.LightGreen1; range.Style.Borders[BordersLineType.EdgeBottom].LineStyle = LineStyleType.Medium; //test data sheet.Range[currentRow, 2].NumberValue = 7.3; sheet.Range[currentRow, 3].NumberValue = 5; ; sheet.Range[currentRow, 4].NumberValue = 8.2; sheet.Range[currentRow, 5].NumberValue = 4; sheet.Range[currentRow, 6].NumberValue = 3; sheet.Range[currentRow, 7].NumberValue = 11.3; MemoryStream buffer = new MemoryStream(); workbook.SaveToStream(buffer); buffer.Position = 0; return buffer; } } }
Imports System.IO Imports System.Windows.Forms Imports Spire.Xls Module Module1 Private Function WriteFormulas() As Stream Dim workbook As Workbook = New Workbook() Dim sheet As Worksheet = workbook.Worksheets(0) Dim currentRow As Integer = 1 Dim currentFormula As String = String.Empty sheet.SetColumnWidth(1, 32) sheet.SetColumnWidth(2, 16) sheet.SetColumnWidth(3, 16) currentRow = currentRow + 1 sheet.Range(currentRow, 1).Value = "Examples of formulas :" currentRow = currentRow + 1 sheet.Range(currentRow, 1).Value = "Test data:" Dim range As CellRange = sheet.Range("A1") range.Style.Font.IsBold = True range.Style.FillPattern = ExcelPatternType.Solid range.Style.KnownColor = ExcelColors.LightGreen1 range.Style.Borders(BordersLineType.EdgeBottom).LineStyle = LineStyleType.Medium 'test data sheet.Range(currentRow, 2).NumberValue = 7.3 sheet.Range(currentRow, 3).NumberValue = 5 sheet.Range(currentRow, 4).NumberValue = 8.2 sheet.Range(currentRow, 5).NumberValue = 4 sheet.Range(currentRow, 6).NumberValue = 3 sheet.Range(currentRow, 7).NumberValue = 11.3 Dim buffer As New MemoryStream() workbook.SaveToStream(buffer) buffer.Position = 0 Return buffer End Function Sub Main() Using buffer As Stream = WriteFormulas() 'load Dim workbook As New Workbook() workbook.LoadFromStream(buffer) 'calculate formula Dim b3 As Object = workbook.CaculateFormulaValue("=Sheet1!$B$3") Dim c3 As Object = workbook.CaculateFormulaValue("=Sheet1!$C$3") Dim formula As String = "=Sheet1!$B$3 + Sheet1!$C$3" Dim value As Object = workbook.CaculateFormulaValue(formula) Dim message As String = _ String.Format("Sheet1!$B$3 = {0}, Sheet1!$C$3 = {1}, {2} = {3}", b3, c3, formula.Substring(1), value) MessageBox.Show(message, "Calculate Formulas") End Using End Sub End Module
Published in
Formulas
Sunday, 01 August 2010 15:55
Data Export Formula in C#, VB.NET
Not needing to have Microsoft Excel installed on the machine, The Spire.DataExport can create Excel spreadsheet. This sample demonstrates how to add formulas into xls.
private void button1_Click(object sender, EventArgs e) { Spire.DataExport.XLS.CellExport cellExport5 = new Spire.DataExport.XLS.CellExport(); cellExport5.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView; cellExport5.ColumnsWidth.AddRange(new object[] { "100", "200"}); cellExport5.DataExported = false; cellExport5.DataFormats.CultureName = "zh-CN"; cellExport5.DataFormats.Currency = "¥#,###,##0.00"; cellExport5.DataFormats.DateTime = "yyyy-M-d H:mm"; cellExport5.DataFormats.Float = "#,###,##0.00"; cellExport5.DataFormats.Integer = "#,###,##0"; cellExport5.DataFormats.Time = "H:mm"; cellExport5.FileName = "formula.xls"; cellExport5.SheetOptions.AggregateFormat.Font.Name = "Arial"; cellExport5.SheetOptions.CustomDataFormat.Font.Name = "Arial"; cellExport5.SheetOptions.DefaultFont.Name = "Arial"; cellExport5.SheetOptions.FooterFormat.Font.Name = "Arial"; cellExport5.SheetOptions.HeaderFormat.Font.Name = "Arial"; cellExport5.SheetOptions.HyperlinkFormat.Font.Color = Spire.DataExport.XLS.CellColor.Blue; cellExport5.SheetOptions.HyperlinkFormat.Font.Name = "Arial"; cellExport5.SheetOptions.HyperlinkFormat.Font.Underline = Spire.DataExport.XLS.XlsFontUnderline.Single; cellExport5.SheetOptions.NoteFormat.Alignment.Horizontal = Spire.DataExport.XLS.HorizontalAlignment.Left; cellExport5.SheetOptions.NoteFormat.Alignment.Vertical = Spire.DataExport.XLS.VerticalAlignment.Top; cellExport5.SheetOptions.NoteFormat.Font.Bold = true; cellExport5.SheetOptions.NoteFormat.Font.Name = "Tahoma"; cellExport5.SheetOptions.NoteFormat.Font.Size = 8F; cellExport5.SheetOptions.TitlesFormat.Font.Bold = true; cellExport5.SheetOptions.TitlesFormat.Font.Name = "Arial"; ushort currentRow = 1; string currentFormula = string.Empty; Spire.DataExport.XLS.Cell cell = null; cellExport5.Cells.Clear(); cellExport5.SetColumnWidth(1, 32); cellExport5.SetColumnWidth(2, 16); cellExport5.SetColumnWidth(3, 16); cell = cellExport5.AddString(1, currentRow++, "Examples of formulas :"); cell.Format.Font.Bold = true; cell.Format.FillStyle.Background = Spire.DataExport.XLS.CellColor.LightGreen; cell.Format.FillStyle.Pattern = Spire.DataExport.XLS.Pattern.Solid; cell.Format.Borders.Bottom.Style = Spire.DataExport.XLS.CellBorderStyle.Medium; cell = cellExport5.AddString(1, ++currentRow, "Test data:"); cell.Format.Font.Bold = true; cell.Format.FillStyle.Background = Spire.DataExport.XLS.CellColor.LightGreen; cell.Format.FillStyle.Pattern = Spire.DataExport.XLS.Pattern.Solid; cell.Format.Borders.Bottom.Style = Spire.DataExport.XLS.CellBorderStyle.Medium; //test data cellExport5.AddNumeric(2, currentRow, 7.3); cellExport5.AddNumeric(3, currentRow, 5); cellExport5.AddNumeric(4, currentRow, 8.2); cellExport5.AddNumeric(5, currentRow, 4); cellExport5.AddNumeric(6, currentRow, 3); cellExport5.AddNumeric(7, currentRow++, 11.3); cell = cellExport5.AddString(1, ++currentRow, "Formulas"); cell.Format.Font.Bold = true; cell.Format.FillStyle.Background = Spire.DataExport.XLS.CellColor.LightGreen; cell.Format.FillStyle.Pattern = Spire.DataExport.XLS.Pattern.Solid; cell.Format.Borders.Bottom.Style = Spire.DataExport.XLS.CellBorderStyle.Medium; cell = cellExport5.AddString(2, currentRow, "Results"); cell.Format.Font.Bold = true; cell.Format.FillStyle.Background = Spire.DataExport.XLS.CellColor.LightGreen; cell.Format.FillStyle.Pattern = Spire.DataExport.XLS.Pattern.Solid; cell.Format.Borders.Bottom.Style = Spire.DataExport.XLS.CellBorderStyle.Medium; //str. currentFormula = "=\"hello\""; cellExport5.AddString(1, ++currentRow, currentFormula); cellExport5.AddFormula(2, currentRow, "=\"hello\""); cellExport5.AddFormula(3, currentRow, "=\"" + new string(new char[] { '\u4f60', '\u597d' }) + "\""); //int. currentFormula = "=300"; cellExport5.AddString(1, ++currentRow, currentFormula); cellExport5.AddFormula(2, currentRow, currentFormula); // float currentFormula = "=3389.639421"; cellExport5.AddString(1, ++currentRow, currentFormula); cellExport5.AddFormula(2, currentRow, currentFormula); //bool. currentFormula = "=false"; cellExport5.AddString(1, ++currentRow, currentFormula); cellExport5.AddFormula(2, currentRow, currentFormula); currentFormula = "=1+2+3+4+5-6-7+8-9"; cellExport5.AddString(1, ++currentRow, currentFormula); cellExport5.AddFormula(2, currentRow, currentFormula); currentFormula = "=33*3/4-2+10"; cellExport5.AddString(1, ++currentRow, currentFormula); cellExport5.AddFormula(2, currentRow, currentFormula); // sheet reference currentFormula = "=Sheet1!$B$3"; cellExport5.AddString(1, ++currentRow, currentFormula); cellExport5.AddFormula(2, currentRow, currentFormula); // sheet area reference currentFormula = "=AVERAGE(Sheet1!$D$3:G$3)"; cellExport5.AddString(1, ++currentRow, currentFormula); cellExport5.AddFormula(2, currentRow, currentFormula); // Functions currentFormula = "=Count(3,5,8,10,2,34)"; cellExport5.AddString(1, ++currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=NOW()"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=SECOND(11)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=MINUTE(12)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=MONTH(9)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=DAY(10)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=TIME(4,5,7)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=DATE(6,4,2)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=RAND()"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=HOUR(12)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=TEXT(\"world\", \"$d\")"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=MOD(5,3)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=WEEKDAY(3)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=YEAR(23)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=NOT(true)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=OR(true)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=AND(TRUE)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=VALUE(30)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=LEN(\"world\")"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=MID(\"world\",4,2)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=ROUND(7,3)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=SIGN(4)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=INT(200)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=ABS(-1.21)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=LN(15)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=EXP(20)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=SQRT(40)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=PI()"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=COS(9)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=SIN(45)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=MAX(10,30)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=MIN(5,7)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=AVERAGE(12,45)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=SUM(18,29)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=IF(4,2,2)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); currentFormula = "=SUBTOTAL(3,Sheet1!B2:E3)"; cellExport5.AddString(1, currentRow, currentFormula); cellExport5.AddFormula(2, currentRow++, currentFormula); cellExport5.SaveToFile(); }
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim cellExport5 As Spire.DataExport.XLS.CellExport cellExport5 = New Spire.DataExport.XLS.CellExport cellExport5.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView cellExport5.ColumnsWidth.AddRange(New Object() {"100", "200"}) cellExport5.DataExported = False cellExport5.DataFormats.CultureName = "zh-CN" cellExport5.DataFormats.Currency = "¥#,###,##0.00" cellExport5.DataFormats.DateTime = "yyyy-M-d H:mm" cellExport5.DataFormats.Float = "#,###,##0.00" cellExport5.DataFormats.Integer = "#,###,##0" cellExport5.DataFormats.Time = "H:mm" cellExport5.FileName = "formula.xls" cellExport5.SheetOptions.AggregateFormat.Font.Name = "Arial" cellExport5.SheetOptions.CustomDataFormat.Font.Name = "Arial" cellExport5.SheetOptions.DefaultFont.Name = "Arial" cellExport5.SheetOptions.FooterFormat.Font.Name = "Arial" cellExport5.SheetOptions.HeaderFormat.Font.Name = "Arial" cellExport5.SheetOptions.HyperlinkFormat.Font.Color = Spire.DataExport.XLS.CellColor.Blue cellExport5.SheetOptions.HyperlinkFormat.Font.Name = "Arial" cellExport5.SheetOptions.HyperlinkFormat.Font.Underline = Spire.DataExport.XLS.XlsFontUnderline.Single cellExport5.SheetOptions.NoteFormat.Alignment.Horizontal = Spire.DataExport.XLS.HorizontalAlignment.Left cellExport5.SheetOptions.NoteFormat.Alignment.Vertical = Spire.DataExport.XLS.VerticalAlignment.Top cellExport5.SheetOptions.NoteFormat.Font.Bold = True cellExport5.SheetOptions.NoteFormat.Font.Name = "Tahoma" cellExport5.SheetOptions.NoteFormat.Font.Size = 8.0! cellExport5.SheetOptions.TitlesFormat.Font.Bold = True cellExport5.SheetOptions.TitlesFormat.Font.Name = "Arial" Dim currentRow As Integer = 1 Dim firstCol As UInt16 = Convert.ToUInt16(1) Dim secondCol As UInt16 = Convert.ToUInt16(2) Dim currentFormula As String = String.Empty Dim cell As cell = Nothing cellExport5.Cells.Clear() cellExport5.SetColumnWidth(System.Convert.ToUInt16(1), System.Convert.ToUInt16(32)) cellExport5.SetColumnWidth(System.Convert.ToUInt16(2), System.Convert.ToUInt16(16)) cellExport5.SetColumnWidth(System.Convert.ToUInt16(3), System.Convert.ToUInt16(16)) cell = cellExport5.AddString(System.Convert.ToUInt16(1), System.Convert.ToUInt16(currentRow), "Examples of formulas :") currentRow += 1 cell.Format.Font.Bold = True cell.Format.FillStyle.Background = CellColor.LightGreen cell.Format.FillStyle.Pattern = Pattern.Solid cell.Format.Borders.Bottom.Style = CellBorderStyle.Medium cell = cellExport5.AddString(System.Convert.ToUInt16(1), System.Convert.ToUInt16(currentRow), "Test data:") currentRow += 1 cell.Format.Font.Bold = True cell.Format.FillStyle.Background = CellColor.LightGreen cell.Format.FillStyle.Pattern = Pattern.Solid cell.Format.Borders.Bottom.Style = CellBorderStyle.Medium 'test data cellExport5.AddNumeric(System.Convert.ToUInt16(2), System.Convert.ToUInt16(currentRow), 7.3) cellExport5.AddNumeric(System.Convert.ToUInt16(3), System.Convert.ToUInt16(currentRow), 5) cellExport5.AddNumeric(System.Convert.ToUInt16(4), System.Convert.ToUInt16(currentRow), 8.2) cellExport5.AddNumeric(System.Convert.ToUInt16(5), System.Convert.ToUInt16(currentRow), 4) cellExport5.AddNumeric(System.Convert.ToUInt16(6), System.Convert.ToUInt16(currentRow), 3) cellExport5.AddNumeric(System.Convert.ToUInt16(7), System.Convert.ToUInt16(currentRow), 11.3) currentRow += 1 currentRow += 1 cell = cellExport5.AddString(Convert.ToUInt16(1), Convert.ToUInt16(currentRow), "Formulas") cell.Format.Font.Bold = True cell.Format.FillStyle.Background = CellColor.LightGreen cell.Format.FillStyle.Pattern = Pattern.Solid cell.Format.Borders.Bottom.Style = CellBorderStyle.Medium cell = cellExport5.AddString(secondCol, Convert.ToUInt16(currentRow), "Results") currentRow += 1 cell.Format.Font.Bold = True cell.Format.FillStyle.Background = CellColor.LightGreen cell.Format.FillStyle.Pattern = Pattern.Solid cell.Format.Borders.Bottom.Style = CellBorderStyle.Medium 'str. currentFormula = "=""hello""" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), "=""hello""") cellExport5.AddFormula(Convert.ToUInt16(3), Convert.ToUInt16(currentRow), "=""" & ChrW(20320) & ChrW(22909) + """") currentRow += 1 'int. currentFormula = "=300" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 ' float currentFormula = "=3389.639421" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 'bool. currentFormula = "=false" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=1+2+3+4+5-6-7+8-9" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=33*3/4-2+10" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 ' sheet reference currentFormula = "=Sheet1!$B$3" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 ' sheet area reference currentFormula = "=AVERAGE(Sheet1!$D$3:G$3)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 ' Functions currentFormula = "=Count(3,5,8,10,2,34)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=NOW()" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=SECOND(11)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=MINUTE(12)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=MONTH(9)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=DAY(10)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=TIME(4,5,7)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=DATE(6,4,2)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=RAND()" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=HOUR(12)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=TEXT(""world"", ""$d"")" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=MOD(5,3)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=WEEKDAY(3)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=YEAR(23)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=NOT(true)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=OR(true)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=AND(TRUE)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=VALUE(30)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=LEN(""world"")" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=MID(""world"",4,2)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=ROUND(7,3)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=SIGN(4)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=INT(200)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=ABS(-1.21)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=LN(15)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=EXP(20)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=SQRT(40)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=PI()" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=COS(9)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=SIN(45)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=MAX(10,30)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=MIN(5,7)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=AVERAGE(12,45)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=SUM(18,29)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=IF(4,2,2)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 currentFormula = "=SUBTOTAL(3,Sheet1!B2:E3)" cellExport5.AddString(firstCol, Convert.ToUInt16(currentRow), currentFormula) cellExport5.AddFormula(secondCol, Convert.ToUInt16(currentRow), currentFormula) currentRow += 1 cellExport5.SaveToFile() End Sub
Published in
Cell