This repository has been archived by the owner on Feb 29, 2024. It is now read-only.
forked from Peter-Conijn/ObjectViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
codeunit 50138 "OVW Export to Excel" | ||
{ | ||
trigger OnRun() | ||
begin | ||
|
||
end; | ||
|
||
procedure Rec2Excel(TableID: Integer) | ||
var | ||
RecRef: RecordRef; | ||
begin | ||
RecRef.Open(TableID); | ||
if not RecRef.ReadPermission then | ||
exit; | ||
|
||
RowNo := 1; | ||
|
||
if RecRef.FindSet() then begin | ||
repeat | ||
Ref2Excel(RecRef, TableID); | ||
until RecRef.Next() = 0; | ||
end; | ||
TempExcelBuffer.CreateExcelBook(RecRef.Name); //change into table name? | ||
end; | ||
|
||
local procedure Ref2Excel(var Ref: RecordRef; TableID: Integer) | ||
var | ||
int: Integer; | ||
begin | ||
ColumnNo := 1; | ||
RowNo += 1; | ||
|
||
for int := 1 to Ref.FieldCount() do begin | ||
fRef2Excel(Ref, int, TableID); | ||
end; | ||
end; | ||
|
||
local procedure fRef2Excel(var Ref: RecordRef; var i: Integer; TableID: Integer) | ||
var | ||
FRef: FieldRef; | ||
begin | ||
FRef := Ref.FieldIndex(i); | ||
|
||
if not IsFieldEnabled(FRef, TableID) then | ||
exit; | ||
|
||
case FRef.Class of | ||
FRef.Class::Normal: | ||
begin | ||
TempExcelBuffer.AddCell(RowNo, ColumnNo, FRef.Value, FRef.Caption, 1); | ||
end; | ||
|
||
FRef.Class::FlowField: | ||
begin | ||
FRef.CalcField(); | ||
TempExcelBuffer.AddCell(RowNo, ColumnNo, FRef.Value, FRef.Caption, 1); | ||
end; | ||
end; | ||
end; | ||
|
||
local procedure IsFieldEnabled(FRef: FieldRef; TableID: Integer): Boolean | ||
var | ||
FieldRecord: Record Field; | ||
begin | ||
if FieldRecord.Get(FRef.Record().Number, FRef.Number) then | ||
exit(FieldRecord.Enabled); | ||
end; | ||
|
||
var | ||
TempExcelBuffer: Record "Excel Buffer" temporary; | ||
ColumnNo: Integer; | ||
RowNo: Integer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
tableextension 50131 "OVW Excel Buffer" extends "Excel Buffer" | ||
{ | ||
fields | ||
{ | ||
field(50131; "OVW Value is BLOB"; Boolean) | ||
{ | ||
DataClassification = SystemMetadata; | ||
} | ||
} | ||
|
||
procedure AddCell(pintRow: Integer; var pintColumn: Integer; pvarValue: Variant; ptxtHeading: Text[250]; pintColumnIncrement: Integer) | ||
begin | ||
AddCellWithFormatting(pintRow, pintColumn, pvarValue, ptxtHeading, false, false, false, 2, pintColumnIncrement); //34764+- | ||
end; | ||
|
||
procedure AddCellWithFormatting(RowNo: Integer; var ColumnNo: Integer; CellValue: Variant; CellHeading: Text[250]; IsBold: Boolean; IsItalic: Boolean; IsUnderlined: Boolean; NumberOfDecimals: Integer; ColumnIncrementValue: Integer) | ||
var | ||
DecimalNotation: Text; | ||
begin | ||
Init(); | ||
Validate("Row No.", RowNo); | ||
Validate("Column No.", ColumnNo); | ||
TestField("Row No."); | ||
TestField("Column No."); | ||
Formula := ''; | ||
Bold := IsBold; | ||
Italic := IsItalic; | ||
Underline := IsUnderlined; | ||
|
||
DecimalNotation := '#,##0'; | ||
if NumberOfDecimals > 0 then begin | ||
DecimalNotation += '.'; | ||
DecimalNotation := PadStr(DecimalNotation, StrLen(DecimalNotation) + NumberOfDecimals, '0'); | ||
end; | ||
|
||
case true of | ||
CellValue.IsInteger, | ||
CellValue.IsDecimal, | ||
CellValue.IsDuration, | ||
CellValue.IsBigInteger: | ||
begin | ||
NumberFormat := '0'; | ||
"Cell Type" := "Cell Type"::Number; | ||
if CellValue.IsDecimal then | ||
NumberFormat := DecimalNotation; | ||
end; | ||
|
||
CellValue.IsDate: | ||
begin | ||
"Cell Type" := "Cell Type"::Date; | ||
end; | ||
|
||
CellValue.IsTime: | ||
begin | ||
"Cell Type" := "Cell Type"::Time; | ||
end; | ||
|
||
CellValue.IsDateTime: | ||
begin | ||
"Cell Type" := "Cell Type"::Date; | ||
end; | ||
|
||
else begin | ||
"Cell Type" := "Cell Type"::Text; | ||
if StrLen(Format(CellValue)) > MaxStrLen("Cell Value as Text") then begin | ||
"OVW Value is BLOB" := true; | ||
ConvertStringToBlob(Format(CellValue), TempBlob); | ||
TempBlob.FromRecord(Rec, FieldNo("Cell Value as Blob")); | ||
end; | ||
end; | ||
end; | ||
if not "OVW Value is BLOB" then | ||
"Cell Value as Text" := Format(CellValue); | ||
if not Insert() then | ||
Modify(); | ||
AddHeading(ColumnNo, CellHeading); | ||
ColumnNo += ColumnIncrementValue; | ||
end; | ||
|
||
[Obsolete('This procedure is no longer used and will be deprecated. This warning will become an error in the future.', '19.1.20220408')] | ||
procedure AddFormula(pintRow: Integer; var pintColumn: Integer; ptxtFormula: Text[250]; ptxtHeading: Text[250]; pintColumnIncrement: Integer) | ||
begin | ||
Init(); | ||
Validate("Row No.", pintRow); | ||
Validate("Column No.", pintColumn); | ||
"Cell Value as Text" := ''; | ||
Formula := ptxtFormula; | ||
if not Insert() then | ||
Modify(); | ||
AddHeading(pintColumn, ptxtHeading); | ||
pintColumn += pintColumnIncrement; | ||
end; | ||
|
||
procedure AddHeading(pintColumn: Integer; ptxtHeading: Text[250]) | ||
begin | ||
AddHeadingAtRow(1, pintColumn, ptxtHeading); | ||
end; | ||
|
||
procedure AddHeadingAtRow(RowNo: Integer; var ColumnNo: Integer; ColumnHeading: Text[250]) | ||
begin | ||
IF ColumnHeading = '' THEN | ||
exit; | ||
if RowNo <> 1 then | ||
ColumnNo += 1; | ||
if Get(RowNo, ColumnNo) then | ||
exit; | ||
Init(); | ||
Validate("Row No.", RowNo); | ||
Validate("Column No.", ColumnNo); | ||
"Cell Value as Text" := ColumnHeading; | ||
Bold := true; | ||
"Cell Type" := "Cell Type"::Text; | ||
Insert(); | ||
end; | ||
|
||
procedure CreateExcelBook(SheetName: Text) | ||
begin | ||
CreateFile(SheetName); | ||
end; | ||
|
||
procedure CreateFile(SheetName: Text) | ||
begin | ||
CreateNewBook(SheetName); | ||
WriteSheet(CopyStr(SheetName, 1, 80), CompanyName, UserId); | ||
CloseBook(); | ||
OpenExcel(); | ||
end; | ||
|
||
[Obsolete('This procedure is no longer used and will be deprecated. This warning will become an error in the future.', '19.1.20220408')] | ||
procedure OnlyCreateFile(SheetName: Text; BookCreated: boolean) | ||
var | ||
FileName: text; | ||
begin | ||
ExcelBookCreated := BookCreated; | ||
NewSheetName := SheetName; | ||
if not BookCreated then | ||
CreateNewBook(SheetName); | ||
|
||
WriteSheet(CopyStr(SheetName, 1, 80), CompanyName, UserId); | ||
if ExcelBookCreated then | ||
SelectOrAddSheet(NewSheetName); | ||
end; | ||
|
||
procedure CreateFileWithoutOpening(ptxtSheetName: Text) | ||
begin | ||
CreateNewBook(ptxtSheetName); | ||
WriteSheet(CopyStr(ptxtSheetName, 1, 80), CompanyName, UserId); | ||
CloseBook(); | ||
end; | ||
|
||
procedure ConvertStringToBlob(Input: Text; var TempBlob: Codeunit "Temp Blob"): Integer | ||
var | ||
WriteStream: OutStream; | ||
begin | ||
TempBlob.CreateOutStream(WriteStream, TextEncoding::UTF8); | ||
WriteStream.WriteText(Input); | ||
end; | ||
|
||
var | ||
TempBlob: Codeunit "Temp Blob"; | ||
|
||
ExcelBookCreated: Boolean; | ||
NewSheetName: text[20]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters