-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
FormNewSpreadsheet.vb
813 lines (624 loc) · 30.4 KB
/
FormNewSpreadsheet.vb
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
Imports System.IO
Imports System.Linq
Imports DWSIM.Interfaces
Imports DWSIM.SharedClassesCSharp.FilePicker
#If LINUX Then
Imports DWSIM.CrossPlatform.UI.Controls.ReoGrid
Imports DWSIM.CrossPlatform.UI.Controls.ReoGrid.Formula
Imports Eto.Forms
Imports Cell = DWSIM.CrossPlatform.UI.Controls.ReoGrid.Cell
#Else
Imports unvell.ReoGrid
Imports unvell.ReoGrid.Formula
#End If
Public Class FormNewSpreadsheet
Protected ccparams As Global.DWSIM.SharedClasses.Spreadsheet.SpreadsheetCellParameters
Public dt1 As New List(Of List(Of Object))
Public dt2 As New List(Of List(Of Object))
#If LINUX Then
Public Property SpreadsheetControl As ReoGridFullControl
#Else
Public Property SpreadsheetControl As unvell.ReoGrid.Editor.ReoGridEditor
#End If
Public Property Flowsheet As FormFlowsheet
Public Property Loaded As Boolean = False
Private Columns As New List(Of String)
#If LINUX Then
Public ReadOnly Property Spreadsheet As ReoGridControl
Get
Return SpreadsheetControl.GridControl
End Get
End Property
#Else
Public ReadOnly Property Spreadsheet As unvell.ReoGrid.ReoGridControl
Get
Return SpreadsheetControl?.grid
End Get
End Property
#End If
Public Sub Initialize()
#If LINUX Then
SpreadsheetControl = New ReoGridFullControl(False)
Dim nativesheet = WinFormsHelpers.ToNative(SpreadsheetControl, True)
nativesheet.Dock = DockStyle.Fill
Controls.Add(nativesheet)
#Else
Worksheet.DefaultRows = 65536
SpreadsheetControl = New unvell.ReoGrid.Editor.ReoGridEditor()
Editor.Common.Shared.IsPro = FormMain.IsPro
Editor.Common.Shared.SaveInPro = Sub(grid)
Dim filePickerForm As IFilePicker = FilePickerService.GetInstance().GetFilePicker()
Dim handler As IVirtualFile = filePickerForm.ShowSaveDialog(
New List(Of FilePickerAllowedType) From {New FilePickerAllowedType("Excel File", "*.xlsx")})
If handler IsNot Nothing Then
Using stream As New MemoryStream()
Try
grid.Save(stream, IO.FileFormat.Excel2007)
handler.Write(stream)
MessageBox.Show(DWSIM.App.GetLocalString("FileSaved"), "DWSIM", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(DWSIM.App.GetLocalString("Erroaosalvararquivo") + ex.Message.ToString, "DWSIM", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Using
End If
End Sub
Editor.Common.Shared.OpenInPro = Sub(grid)
Dim filePickerForm As IFilePicker = FilePickerService.GetInstance().GetFilePicker()
Dim handler As IVirtualFile = filePickerForm.ShowOpenDialog(
New List(Of FilePickerAllowedType) From {New FilePickerAllowedType("Excel File", "*.xlsx")})
If handler IsNot Nothing Then
Using str = handler.OpenRead()
Try
grid.Load(str, IO.FileFormat.Excel2007)
Catch ex As Exception
MessageBox.Show(DWSIM.App.GetLocalString("Error loading file") + ex.Message.ToString, "DWSIM", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Using
End If
End Sub
Dim h1 = Sub(s2, e2)
Dim frmps As New FormPropSelection
frmps.ssheet = Spreadsheet
frmps.ShowDialog(Me)
End Sub
AddHandler SpreadsheetControl.ImportarDadosToolStripMenuItem.Click, h1
Dim h2 = Sub(s2, e2)
Dim frmps As New FormPropSelection
frmps.ssheet = Spreadsheet
frmps.mode = 1
frmps.ShowDialog(Me)
End Sub
AddHandler SpreadsheetControl.ExportarDadosToolStripMenuItem.Click, h2
Dim h3 = Sub(s2, e2)
CreateChartFromRange(s2, e2)
End Sub
AddHandler SpreadsheetControl.create2DXYChartFromSelectionToolStripMenuItem.Click, h3
AddHandler Me.Closed, Sub(s2, e2)
RemoveHandler SpreadsheetControl.ImportarDadosToolStripMenuItem.Click, h1
RemoveHandler SpreadsheetControl.ExportarDadosToolStripMenuItem.Click, h2
RemoveHandler SpreadsheetControl.create2DXYChartFromSelectionToolStripMenuItem.Click, h3
End Sub
SpreadsheetControl.Dock = DockStyle.Fill
SpreadsheetControl.SetupUILanguage()
Controls.Add(SpreadsheetControl)
#End If
Spreadsheet.CurrentWorksheet.Name = "MAIN"
#If Not LINUX Then
SpreadsheetControl.NewDocumentOnLoad = False
#End If
Columns.AddRange({"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"})
Spreadsheet.CurrentWorksheet.SelectionForwardDirection = SelectionForwardDirection.Down
Spreadsheet.CurrentWorksheet.SetSettings(WorksheetSettings.Formula_AutoUpdateReferenceCell, True)
Spreadsheet.CurrentWorksheet.SetSettings(WorksheetSettings.Formula_AutoPickingCellAddress, True)
Spreadsheet.CurrentWorksheet.SetSettings(WorksheetSettings.Formula_AutoFormat, True)
AddHandler Spreadsheet.WorksheetCreated,
Sub(sender, e)
e.Worksheet.SelectionForwardDirection = SelectionForwardDirection.Down
e.Worksheet.SetSettings(WorksheetSettings.Formula_AutoUpdateReferenceCell, True)
e.Worksheet.SetSettings(WorksheetSettings.Formula_AutoPickingCellAddress, True)
e.Worksheet.SetSettings(WorksheetSettings.Formula_AutoFormat, True)
End Sub
Loaded = True
ExtensionMethods.ChangeDefaultFont(Me)
End Sub
Sub CreateChartFromRange(sender As Object, e As EventArgs)
Dim tabpage As New System.Windows.Forms.TabPage
Dim chart As New Charts.Chart
Dim data = Spreadsheet.CurrentWorksheet.GetRangeData(Spreadsheet.CurrentWorksheet.SelectionRange)
Dim firstcol, lastcol, firstrow, lastrow As Integer
firstcol = Spreadsheet.CurrentWorksheet.SelectionRange.Col
lastcol = Spreadsheet.CurrentWorksheet.SelectionRange.EndCol
firstrow = Spreadsheet.CurrentWorksheet.SelectionRange.Row + 1
lastrow = Spreadsheet.CurrentWorksheet.SelectionRange.EndRow + 1
Dim hasheaders As Boolean = Not Double.TryParse(Spreadsheet.CurrentWorksheet.Cells(firstrow - 1, firstcol).Data, New Double)
Dim name = Spreadsheet.CurrentWorksheet.Name
Dim xcol As String = Spreadsheet.CurrentWorksheet.SelectionRange.StartPos.ToAddress().Trim(New Char() {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"})
Dim ycols As New List(Of String)
For i As Integer = firstcol + 1 To lastcol
ycols.Add(Spreadsheet.CurrentWorksheet.Cells(0, i).Address().Trim(New Char() {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}))
Next
If hasheaders Then
firstrow += 1
End If
For Each item In ycols
chart.SpreadsheetDataSourcesX.Add(name & "!" & xcol & firstrow & ":" & xcol & lastrow)
chart.SpreadsheetDataSourcesY.Add(name & "!" & item & firstrow & ":" & item & lastrow)
Next
Dim chartcontrol = New TwoDimChartControl() With {.Dock = DockStyle.Fill,
.Flowsheet = Flowsheet,
.Chart = chart,
.Spreadsheet = Flowsheet.FormSpreadsheet.Spreadsheet}
tabpage.Controls.Add(chartcontrol)
If hasheaders Then
chartcontrol.UpdatePlotModelData()
Dim j = 0
For i As Integer = firstcol + 1 To lastcol
DirectCast(chart.PlotModel, OxyPlot.PlotModel).Series(j).Title =
Spreadsheet.CurrentWorksheet.Cells(firstrow - 2, i).Data
j += 1
Next
DirectCast(chart.PlotModel, OxyPlot.PlotModel).Axes(0).Title =
Spreadsheet.CurrentWorksheet.Cells(firstrow - 2, firstcol).Data
DirectCast(chart.PlotModel, OxyPlot.PlotModel).Axes(1).Title = ""
If DirectCast(chart.PlotModel, OxyPlot.PlotModel).Series.Count = 1 Then
DirectCast(chart.PlotModel, OxyPlot.PlotModel).Axes(1).Title =
Spreadsheet.CurrentWorksheet.Cells(firstrow - 2, firstcol + 1).Data
End If
End If
tabpage.Text = chart.DisplayName
Flowsheet.Charts.Add(chart.ID, chart)
Flowsheet.FormCharts.TabControl1.TabPages.Add(tabpage)
Flowsheet.FormCharts.Activate()
Flowsheet.FormCharts.TabControl1.SelectedTab = tabpage
End Sub
Private Sub FormNewSpreadsheet_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If Not Loaded Then
Initialize()
CopyFromDT()
End If
#If Not LINUX Then
MoveSpreadsheetMenu()
#End If
SetCustomFunctions()
End Sub
Dim c1, c2, c3, c4, c5, c6 As Func(Of Cell, Object(), Object)
Public Sub SetCustomFunctions()
c1 = Function(cell, args) As Object
Try
Dim obj = Flowsheet.SimulationObjects(args(0).ToString)
Return obj.GraphicObject.Tag
Catch ex As Exception
Return "ERROR: " & ex.Message
End Try
End Function
Formula.FormulaExtension.CustomFunctions("GETNAME") = c1
c2 = Function(cell, args) As Object
If args.Length = 2 Then
Try
Return Flowsheet.SimulationObjects(args(0).ToString).GetPropertyValue(args(1).ToString)
Catch ex As Exception
Return "ERROR: " & ex.Message
End Try
ElseIf args.Length = 3 Then
Try
Dim obj = Flowsheet.SimulationObjects(args(0).ToString)
Dim val = obj.GetPropertyValue(args(1).ToString)
Return ConvertUnits(Double.Parse(val), obj.GetPropertyUnit(args(1).ToString), args(2).ToString)
Catch ex As Exception
Return "ERROR: " & ex.Message
End Try
Else
Return "INVALID ARGS"
End If
End Function
Formula.FormulaExtension.CustomFunctions("GETPROPVAL") = c2
c3 = Function(cell, args) As Object
If args.Length = 3 Then
Try
Dim ws = cell.Worksheet
Dim wcell = ws.Cells(ws.RowCount - 1, ws.ColumnCount - 1)
wcell.Formula = args(2).ToString.Trim(Chr(34))
Evaluator.Evaluate(wcell)
Dim val = wcell.Data
Flowsheet.SimulationObjects(args(0).ToString).SetPropertyValue(args(1).ToString, val)
wcell.Formula = ""
wcell.Data = ""
Return String.Format("EXPORT OK [{0}, {1} = {2}]", Flowsheet.SimulationObjects(args(0).ToString).GraphicObject.Tag, args(1).ToString, val)
Catch ex As Exception
Return "ERROR: " & ex.Message
End Try
ElseIf args.Length = 4 Then
Try
Dim obj = Flowsheet.SimulationObjects(args(0).ToString)
Dim prop = args(1).ToString
Dim ws = cell.Worksheet
Dim wcell = ws.Cells(ws.RowCount - 1, ws.ColumnCount - 1)
wcell.Formula = args(2).ToString.Trim(Chr(34))
Evaluator.Evaluate(wcell)
Dim val = wcell.Data
wcell.Formula = ""
wcell.Data = ""
Dim units = args(3).ToString
Dim newval = ConvertUnits(Double.Parse(val), units, obj.GetPropertyUnit(prop))
obj.SetPropertyValue(prop, newval)
Return String.Format("EXPORT OK [{0}, {1} = {2} {3}]", obj.GraphicObject.Tag, prop, val, units)
Catch ex As Exception
Return "ERROR: " & ex.Message
End Try
Else
Return "INVALID ARGS"
End If
End Function
Formula.FormulaExtension.CustomFunctions("SETPROPVAL") = c3
c4 = Function(cell, args) As Object
If args.Length = 2 Then
Try
Return Flowsheet.SimulationObjects(args(0).ToString).GetPropertyUnit(args(1).ToString)
Catch ex As Exception
Return "ERROR: " & ex.Message
End Try
Else
Return "INVALID ARGS"
End If
End Function
Formula.FormulaExtension.CustomFunctions("GETPROPUNITS") = c4
c5 = Function(cell, args) As Object
If args.Length = 1 Then
Try
Return Flowsheet.GetFlowsheetSimulationObject(args(0).ToString).Name
Catch ex As Exception
Return "ERROR: " & ex.Message
End Try
Else
Return "INVALID ARGS"
End If
End Function
Formula.FormulaExtension.CustomFunctions("GETOBJID") = c5
c6 = Function(cell, args) As Object
If args.Length = 1 Then
Try
Return Flowsheet.SimulationObjects(args(0).ToString).GraphicObject.Tag
Catch ex As Exception
Return "ERROR: " & ex.Message
End Try
Else
Return "INVALID ARGS"
End If
End Function
Formula.FormulaExtension.CustomFunctions("GETOBJNAME") = c6
End Sub
Public Sub MoveSpreadsheetMenu()
#If Not LINUX Then
Dim menustrip1 As MenuStrip = SpreadsheetControl.SpreadsheetTSMI.GetCurrentParent()
menustrip1.Items.Remove(SpreadsheetControl.SpreadsheetTSMI)
Flowsheet.MenuStrip1.Items.Insert(4, SpreadsheetControl.SpreadsheetTSMI)
SpreadsheetControl.SpreadsheetTSMI.Enabled = False
#End If
End Sub
Public Function GetCellValue(address As String) As Cell
Return Spreadsheet.Worksheets(0).Cells(address)
End Function
Public Sub SetCellValue(ByVal cell As String, value As Object)
Spreadsheet.Worksheets(0).Cells(cell).Data = value
End Sub
Public Sub EvaluateAll()
Try
Spreadsheet?.Worksheets(0).Recalculate()
Catch ex As Exception
End Try
End Sub
Public Sub WriteAll()
For Each ws In Spreadsheet.Worksheets
ws.Recalculate()
Next
End Sub
Public Function GetCellString() As String()
Dim celllist As New List(Of String)
For Each item In Columns
For i As Integer = 1 To 100
celllist.Add(item & i.ToString)
Next
Next
Return celllist.ToArray
End Function
Public Function GetCellString(ByVal cell As Cell) As String
Return cell.Address
End Function
Public Sub CopyToDT()
Dim i, j As Integer
dt1 = New List(Of List(Of Object))
dt2 = New List(Of List(Of Object))
Dim c As Cell
For i = 0 To Spreadsheet.Worksheets(0).MaxContentRow - 1
dt1.Add(New List(Of Object))
dt2.Add(New List(Of Object))
For j = 0 To Spreadsheet.Worksheets(0).MaxContentCol - 1
c = Spreadsheet.Worksheets(0).Cells(i, j)
Try
dt1(i).Add(c.Data)
Catch ex As Exception
End Try
Try
dt2(i).Add(c.Tag)
Catch ex As Exception
End Try
Next
Next
End Sub
Public Function CopyDT1ToString() As String
Dim ci As Globalization.CultureInfo = Globalization.CultureInfo.InvariantCulture
Dim text As String = ""
For i As Integer = 0 To dt1.Count - 1
For j As Integer = 0 To dt1(0).Count - 1
If dt1.Count - 1 >= i AndAlso dt1(0).Count - 1 >= j Then
If Double.TryParse(dt1(i)(j), Globalization.NumberStyles.Any, ci, New Double) Then
text += Double.Parse(dt1(i)(j), ci).ToString & ";"
Else
If dt1(i)(j) IsNot Nothing Then
text += dt1(i)(j).ToString() & ";"
Else
text += ";"
End If
End If
End If
Next
text = text.TrimEnd(";") & "|"
Next
text = text.TrimEnd("|")
Return text
End Function
Public Function CopyDT2ToString() As String
Dim ci As Globalization.CultureInfo = Globalization.CultureInfo.InvariantCulture
Dim text As String = ""
For i As Integer = 0 To dt2.Count - 1
For j As Integer = 0 To dt1(0).Count - 1
If dt2.Count - 1 >= i AndAlso dt2(0).Count - 1 >= j Then
If Not dt2(i)(j) Is Nothing Then
Try
Dim xel As New XElement("dummy", DirectCast(dt2(i)(j), Spreadsheet.SpreadsheetCellParameters).SaveData.ToArray)
text += xel.ToString + ";"
Catch ex As Exception
text += " ;"
End Try
Else
text += " ;"
End If
End If
Next
text = text.TrimEnd(";") + "|"
Next
text = text.TrimEnd("|")
Return text
End Function
Public Sub CopyDT1FromString(text As String)
Dim rows() As String = text.Split("|")
Dim n As Integer = rows.Length - 1
Dim m As Integer = 0
Dim value As Object
Dim ci = System.Globalization.CultureInfo.InvariantCulture
Dim format = Globalization.NumberStyles.Any - Globalization.NumberStyles.AllowThousands
If n > 0 Then
m = rows(0).Split(";").Length - 1
End If
If n > 0 And m > 0 Then
Dim elm As New List(Of List(Of Object))
Try
For i As Integer = 0 To n
elm.Add(New List(Of Object))
If n > 0 Then
m = rows(i).Split(";").Length - 1
End If
For j As Integer = 0 To m
value = rows(i).Split(";")(j)
If Double.TryParse(value, format, ci, New Double) Then
elm(i).Add(Double.Parse(value, format, ci))
Else
elm(i).Add(value)
End If
Next
Next
Catch ex As Exception
End Try
dt1 = elm
End If
End Sub
Public Sub CopyDT2FromString(text As String)
Dim rows() As String = text.Split("|")
Dim n As Integer = rows.Length - 1
Dim m As Integer = 0
If n > 0 Then
m = rows(0).Split(";").Length - 1
End If
If n > 0 And m > 0 Then
Dim elm As New List(Of List(Of Object))
For i As Integer = 0 To n
elm.Add(New List(Of Object))
For j As Integer = 0 To m
Dim scp As New Spreadsheet.SpreadsheetCellParameters()
Try
Dim element As New XElement("dummy")
Dim text0 = rows(i).Replace(">", "greater_than").Replace("<", "less_than")
Dim xmltext As String = text0.Split(";")(j)
If xmltext <> " " Then
Dim text1 = xmltext.Replace("greater_than", ">").Replace("less_than", "<")
element = XElement.Parse(text1)
scp.LoadData(element.Elements.ToList)
elm(i).Add(scp)
Else
elm(i).Add(scp)
End If
Catch ex As Exception
End Try
Next
Next
dt2 = elm
End If
End Sub
Public Sub CopyFromDT()
Dim i, j, n1, m1, n2, m2, maxrow, maxcol As Integer
n1 = dt1.Count - 1
If n1 = -1 Then Exit Sub
m1 = dt1(0).Count - 1
n2 = dt2.Count - 1
m2 = dt2(0).Count - 1
maxrow = Spreadsheet.Worksheets(0).RowCount - 1
maxcol = Spreadsheet.Worksheets(0).ColumnCount - 1
Dim sheet = Spreadsheet.Worksheets(0)
For i = 0 To n1
For j = 0 To m1
If i <= maxrow And j <= dt1(i).Count - 1 Then
If dt1(i)(j) IsNot Nothing Then sheet.Cells(i, j).Data = dt1(i)(j)
End If
If i <= n2 And j <= dt2(i).Count Then
If dt2(i)(j) Is Nothing Then
sheet.Cells(i, j).Tag = New Spreadsheet.SpreadsheetCellParameters
ElseIf TypeOf dt2(i)(j) Is Spreadsheet.SpreadsheetCellParameters Then
sheet.Cells(i, j).Tag = dt2(i)(j)
ElseIf TypeOf dt2(i)(j) Is Object Then
Dim cellparam As New Spreadsheet.SpreadsheetCellParameters
Try
With cellparam
.Expression = dt2(i)(j)
If CStr(dt2(i)(j)).StartsWith(":") Then
.CellType = SharedClasses.Spreadsheet.VarType.Read
Dim str As String()
str = CStr(dt2(i)(j)).Split(New Char() {","})
.ObjectID = str(0).Substring(1)
.PropID = str(1)
Else
.CellType = SharedClasses.Spreadsheet.VarType.Expression
End If
End With
Catch ex As Exception
End Try
sheet.Cells(i, j).Tag = cellparam
End If
End If
Next
Next
ParseOldData()
End Sub
Sub ParseOldData()
'Dim separator = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ListSeparator
Dim separator = ";"
Dim esheet = Spreadsheet.NewWorksheet("EXPORTS")
Dim elist As New List(Of Tuple(Of String, String, String, String))
Dim i, j As Integer
Dim cell As Cell
For i = 0 To Spreadsheet.Worksheets(0).RowCount - 1
For j = 0 To Spreadsheet.Worksheets(0).ColumnCount - 1
cell = Spreadsheet.Worksheets(0).Cells(i, j)
ccparams = cell.Tag
If Not ccparams Is Nothing Then
Dim expression = ccparams.Expression
Select Case ccparams.CellType
Case SharedClasses.Spreadsheet.VarType.Expression, SharedClasses.Spreadsheet.VarType.Read
If expression <> "" Then
If expression.Substring(0, 1) = "=" Then
cell.Formula = expression.TrimStart("=").ToUpper()
#If Not LINUX Then
If Not ccparams.CellType = SharedClasses.Spreadsheet.VarType.Write Then cell.Style.BackColor = Color.LightYellow
#End If
ElseIf expression.Substring(0, 1) = ":" Then
Dim str As String()
Dim obj, prop As String
str = expression.Split(New Char() {","})
obj = str(0).Substring(1)
ccparams.ObjectID = obj
If str.Length < 3 Then
prop = str(1)
Else
prop = str(1) & "," & str(2)
End If
ccparams.PropID = prop
cell.Formula = String.Format("GETPROPVAL({3}{0}{3}{1}{3}{2}{3})", obj, separator, prop, Chr(34))
'ccparams.ToolTipText = DWSIM.App.GetLocalString("CellIsReading") & vbCrLf &
'DWSIM.App.GetLocalString("Objeto") & ": " & formc.Collections.FlowsheetObjectCollection(ccparams.ObjectID).GraphicObject.Tag & vbCrLf &
'DWSIM.App.GetLocalString("Propriedade") & ": " & DWSIM.App.GetPropertyName(prop) & vbCrLf &
'DWSIM.App.GetLocalString("CurrentValue") & ": " & cell.Value &
'" " & formc.Collections.FlowsheetObjectCollection(obj).GetPropertyUnit(prop, formc.Options.SelectedUnitSystem)
#If Not LINUX Then
cell.Style.BackColor = Color.LightGreen
#End If
Else
cell.Data = expression
If ccparams.CellType <> SharedClasses.Spreadsheet.VarType.Write And ccparams.CellType <> SharedClasses.Spreadsheet.VarType.Unit Then
ccparams.ToolTipText = expression
End If
End If
End If
Case SharedClasses.Spreadsheet.VarType.Unit
#If Not LINUX Then
cell.Style.BackColor = Color.Beige
#End If
Case SharedClasses.Spreadsheet.VarType.Write
If expression.Substring(0, 1) = "=" Then
cell.Formula = expression.TrimStart("=").ToUpper()
#If Not LINUX Then
If Not ccparams.CellType = SharedClasses.Spreadsheet.VarType.Write Then cell.Style.BackColor = Color.LightYellow
#End If
Else
cell.Data = expression
If ccparams.CellType <> SharedClasses.Spreadsheet.VarType.Write And ccparams.CellType <> SharedClasses.Spreadsheet.VarType.Unit Then
ccparams.ToolTipText = expression
End If
End If
elist.Add(New Tuple(Of String, String, String, String)(String.Format("SETPROPVAL({4}{1}{4}{0}{4}{2}{4}{0}{4}{3}{4})", separator, ccparams.ObjectID, ccparams.PropID, "MAIN!" & cell.Address, Chr(34)),
ccparams.ObjectID, ccparams.PropID, ccparams.PropUnit))
#If Not LINUX Then
cell.Style.BackColor = Color.LightBlue
#End If
End Select
End If
Next
Next
esheet.Cells(0, 0).Data = "EXPRESSION"
esheet.Cells(0, 1).Data = "OBJECT"
esheet.Cells(0, 2).Data = "PROPERTY"
esheet.Cells(0, 3).Data = "UNITS"
esheet.Cells(0, 0).Style.Bold = True
esheet.Cells(0, 1).Style.Bold = True
esheet.Cells(0, 2).Style.Bold = True
esheet.Cells(0, 3).Style.Bold = True
i = 1
For Each item In elist
esheet.Cells(i, 0).Formula = item.Item1
esheet.Cells(i, 1).Data = Flowsheet.SimulationObjects(item.Item2).GraphicObject.Tag
esheet.Cells(i, 2).Data = item.Item3
esheet.Cells(i, 3).Data = item.Item4
Next
End Sub
Private Sub FormNewSpreadsheet_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Dim sheet = Spreadsheet.NewWorksheet("DUMMY1234567890")
Spreadsheet.CurrentWorksheet = Spreadsheet.Worksheets("DUMMY1234567890")
Spreadsheet.CurrentWorksheet = Spreadsheet.Worksheets(0)
Spreadsheet.RemoveWorksheet(sheet)
For Each sheet In Spreadsheet.Worksheets
If sheet.ScaleFactor < Settings.DpiScale Then sheet.ScaleFactor = Settings.DpiScale
Next
FormMain.TranslateFormFunction?.Invoke(Me)
End Sub
Public Sub ReleaseResources()
Formula.FormulaExtension.CustomFunctions.Clear()
c1 = Nothing
c2 = Nothing
c3 = Nothing
c4 = Nothing
c5 = Nothing
c6 = Nothing
#If Not LINUX Then
Try
Flowsheet?.MenuStrip1.Items.Remove(SpreadsheetControl.SpreadsheetTSMI)
SpreadsheetControl?.SpreadsheetTSMI.Dispose()
Catch ex As Exception
End Try
#End If
SpreadsheetControl.Dispose()
SpreadsheetControl = Nothing
End Sub
#If Not LINUX Then
Private Sub FormNewSpreadsheet_VisibleChanged(sender As Object, e As EventArgs) Handles Me.VisibleChanged
If SpreadsheetControl IsNot Nothing Then SpreadsheetControl.SpreadsheetTSMI.Enabled = Me.Visible
End Sub
#End If
End Class