This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
/
Form1.cs
46 lines (42 loc) · 1.72 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace UDF_Discount
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
#region #AddFunction
DiscountFunction udfFunction = new DiscountFunction();
if (!spreadsheetControl1.Document.CustomFunctions.Contains(udfFunction.Name))
spreadsheetControl1.Document.CustomFunctions.Add(udfFunction);
#endregion #AddFunction
spreadsheetControl1.DocumentLoaded+=spreadsheetControl1_DocumentLoaded;
spreadsheetControl1.LoadDocument("Discount.xlsx");
}
private void spreadsheetControl1_DocumentLoaded(object sender, EventArgs e)
{
#region #GetExistingCells
IEnumerable<DevExpress.Spreadsheet.Cell> existingCells = spreadsheetControl1.ActiveWorksheet.GetExistingCells();
spreadsheetControl1.Document.BeginUpdate();
foreach (DevExpress.Spreadsheet.Cell cell in existingCells)
{
if (cell.HasFormula)
// The worksheet references functions from the DiscountXLL.MyFunctions xll Add-in.
// The name prefix is removed leaving only the function name.
cell.Formula = cell.Formula.Replace("_xll.DiscountXLL.MyFunctions.", string.Empty);
}
spreadsheetControl1.Document.EndUpdate();
#endregion #GetExistingCells
spreadsheetControl1.ActiveWorksheet.ScrollToRow(0);
}
}
}