From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00,FREEMAIL_FROM, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Received: by 2002:a05:620a:10b6:b0:74e:2e3:8e24 with SMTP id h22-20020a05620a10b600b0074e02e38e24mr478716qkk.6.1682017720939; Thu, 20 Apr 2023 12:08:40 -0700 (PDT) X-Received: by 2002:a81:ac41:0:b0:545:f7cc:f30 with SMTP id z1-20020a81ac41000000b00545f7cc0f30mr1230895ywj.0.1682017720779; Thu, 20 Apr 2023 12:08:40 -0700 (PDT) Path: eternal-september.org!news.eternal-september.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Thu, 20 Apr 2023 12:08:40 -0700 (PDT) In-Reply-To: Injection-Info: google-groups.googlegroups.com; posting-host=2a02:1210:2e90:8100:ed16:afa:6e63:c227; posting-account=gRqrnQkAAAAC_02ynnhqGk1VRQlve6ZG NNTP-Posting-Host: 2a02:1210:2e90:8100:ed16:afa:6e63:c227 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <1205879c-cbef-4a87-b3a5-94f9db91f2f0n@googlegroups.com> Subject: Re: Ada interface to Excel file From: Gautier write-only address Injection-Date: Thu, 20 Apr 2023 19:08:40 +0000 Content-Type: text/plain; charset="UTF-8" Xref: news.eternal-september.org comp.lang.ada:65122 List-Id: The simplest way by far is to generate the Ada sources from within Excel by using VBA (a BASIC with a strong Ada flavour, but still a BASIC) which is part of Excel. >From Excel, you activate VBA with the Alt-F11 shortcut. You have "modules" which are just editor files and visible from everywhere else (you have like implicit "with"'s and "use"'s); you have functions called "Function" and procedures called "Sub". You can associate a button in the Excel sheet to a Sub. You declare each variable with "Dim x As Type". You can also forget to declare variables, with funny outcomes. The behavious of the type system around parameter passing is also funny. You find below a few examples. Now, if you already have your CSV-to-Ada generator, you can export a CSV; that's also easy with VBA. G. [somewhere (some module)] Sub Generate_for_Production() Dim anchor As String ' VBA String is Ada's Unbounded_String ' File handles Dim fh_ada_spec As Integer Dim fh_ada_body As Integer ... Open ThisWorkbook.Path & "\src\" & pkg_name & _ ".ads" For Output As #fh_ada_spec ... For Each ws In Worksheets ' Scan all worksheets For Each r In ws.UsedRange.Rows ' Scan all used rows anchor = r.Cells(1, 1).Value If anchor <> "" Then ... End If Next r Next ws ... Close #fh_ada_spec End Sub [somewhere else (perhaps another module)] Print #fh, "with Ada.Calendar;" Print #fh, "with Ada.Unchecked_Conversion;" Print #fh, "with Interfaces;" Print #fh, Print #fh, "package " & name & " is" [somewhere else] If simple_record Then Print #fh_ada_spec, " -- Simple record." Print #fh_ada_spec, Print #fh_ada_spec, " type Xyz is record -- " & paragraph Else Print #fh_ada_spec, " type Xyz is new " & parent_name & _ "Abc with record -- " & paragraph End If [somewhere else] For i = min_row_offset To max_row_offset ' Convert name in cell to Ada name field = Ada_Name(r.Cells(i, 3).Value) If field = "" Then Exit For End If amount = r.Cells(i, 6).Value ... Print #fh_ada_body, " for index in 1 .. " & amount & " loop" Print #fh_ada_body, " declare"