Create an excel workbook/worksheet in Altium DelphiScript without installing plugins

897 Views Asked by At

I am currently extracting the Pin List - Pin Names in Altium Designer that uses DelphiScript (not Delphi). DelphiScript and Delphi has differences and I believe one of them is the file I/O component. According to the Altium Docs for DelphiScript, only text files and csv files can be produced. In producing an output file .csv, saving is as easy as throwing text that are comma delimited and then saving with an extension '.csv'. My problem now is how to create a .xls file without importing and/or downloading plugins/extensions like eDocEngine VCL, LibXL, TQExport4Xlsx. Tried declaring TBook, TSheet, TgtXLSEngine or other ways to create the spreadsheet but error says it is an undeclared identifier. Do you guys have any idea?

Report Writer Code Snippet:


Procedure BeginReportPinList(AFilename: String);
Begin
    gv_FileName := AFilename + '.csv'; 
    AssignFile(gv_FileReport, gv_FileName);
    Rewrite(gv_FileReport);
End;

Procedure WriteReportDUT(AReport : String);
Begin
    WriteLn(gv_FileReport, Format('%s', [AReport]));
End;

Procedure EndReport(Dummy : Boolean);
Begin
    CloseFile(gv_FileReport);
End;


String Parser Code Snippet that calls above procedures:

if dutlistX.Count = 1 then
       Begin

            PinFilename := copy(gv_Board.FileName, 1, Pos('-05', gv_Board.FileName)-1) + '-14';
            BeginReportPinList(PinFilename);

            For I := 0 To finalreport.Count - 1 Do
                Begin
                     WriteReportDUT(finalreport[I]);
                End;

            EndReport(0);
      End;
1

There are 1 best solutions below

0
Victor Kryshtapovich On

As was mentioned in comments by @Ken White, it is very difficult to do this without third-party components. As far as I know, XSL file has a structure of Compound File Binary Format. This type of files consisting of blocks and streams that You can manipulate. I have used this third-party software to parse such file type (actually SchDoc, but not XLS), check this question. OpenMCDF can do a trick if You have Altium running with .NET platform, like 16 version do, for example. In addition, You may use the specification of this file format based on CFB.

It is very noticeable, that some other filetypes of Altium is using that CFB file format, so it might be useful to know about OpenMCDF. I believe that XLS can be created in much handy way, than this one, but it is useful to know, how to deal with such data containers, as XLS, or SchDoc, et cetera.