Author Topic: Read from a spreadsheet ( excel or google doc )  (Read 3720 times)

Malic

  • Full Member
  • ***
  • Posts: 105
Read from a spreadsheet ( excel or google doc )
« on: April 15, 2017, 04:47:04 AM »
I am trying to create a command for Elite Dangerous in which you can ask it witht he Prefix "What is needed for" and then suffix of something like "HEAVY DUTY ARMOUR 1;HEAVY DUTY ARMOUR 2;HEAVY DUTY ARMOUR 3;HEAVY DUTY ARMOUR 4;HEAVY DUTY ARMOUR 5"

What I am hoping to do is to have the last bit instead as a wildcard, and maybe have it look in column 1 for that phrase, and then take the items in columns 2-4 and save each to a variable so then they can be read out loud with TTS

Right now I am doing it with a very long command which just entering each line by line is tedious.

Example below is for one set of blueprints, grade 1-5, there are a huge listing of them and would rather have a spreadsheet to edit on google so if I make it public, I can edit it there and not have to update it for several people when it changes in game.

Quote
Begin Text Compare : [{SUFFIX}] Equals '0'
Else If Text Compare : [{SUFFIX}] Equals 'HEAVY DUTY ARMOUR 1'
Set Text [Engineer Mat 1] to 'Carbon'
Set Text [Engineer Mat 2] to ''
Set Text [Engineer Mat 3] to ''
Set Text [Engineer Mat 4] to ''
Else If Text Compare : [{SUFFIX}] Equals 'HEAVY DUTY ARMOUR 2'
Set Text [Engineer Mat 1] to 'Carbon'
Set Text [Engineer Mat 2] to 'Shield Emitters'
Set Text [Engineer Mat 3] to 'Articulation Motors'
Set Text [Engineer Mat 4] to ''
Else If Text Compare : [{SUFFIX}] Equals 'HEAVY DUTY ARMOUR 3'
Set Text [Engineer Mat 1] to 'Carbon'
Set Text [Engineer Mat 2] to 'High Density Composites'
Set Text [Engineer Mat 3] to 'Shield Emitters'
Set Text [Engineer Mat 4] to 'Reinforced Mounting Plate'
Else If Text Compare : [{SUFFIX}] Equals 'HEAVY DUTY ARMOUR 4'
Set Text [Engineer Mat 1] to 'Proprietary Composites'
Set Text [Engineer Mat 2] to 'Shielding Sensors'
Set Text [Engineer Mat 3] to 'Vanadium'
Set Text [Engineer Mat 4] to 'Reinforced Mounting Plate'
Else If Text Compare : [{SUFFIX}] Equals 'HEAVY DUTY ARMOUR 5'
Set Text [Engineer Mat 1] to 'Compound Shielding'
Set Text [Engineer Mat 2] to 'Core Dynamics Composites'
Set Text [Engineer Mat 3] to 'Tungsten'
Set Text [Engineer Mat 4] to 'Reinforced Mounting Plate'
Else
    Set small int (condition) [EDSIQuantity] value to the converted value of {SUFFIX}
End Condition
Say, '{TXT:Engineer Mat 1}, {TXT:Engineer Mat 2}, {TXT:Engineer Mat 3}, {TXT:Engineer Mat 4}
Set Windows clipboard to '{TXT:Engineer Mat 1}, {TXT:Engineer Mat 2}, {TXT:Engineer Mat 3}''


Reason why i have it save each to separate variables is there are another series fo commands where you can sk it "what was the second item" to repeat just that. 

Pfeil

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4780
  • RTFM
Re: Read from a spreadsheet ( excel or google doc )
« Reply #1 on: April 15, 2017, 08:19:34 AM »
have a spreadsheet to edit on google so if I make it public, I can edit it there and not have to update it for several people when it changes in game.
Google Sheets does have an API, so you could write a VoiceAttack plugin to interface with it.

I see the utility in having it always-online for updates, but if you drop that requirement it's probably easier to export the sheet to a .csv and have a plugin read that instead.

Antaniserse

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 87
    • My VA plugins
Re: Read from a spreadsheet ( excel or google doc )
« Reply #2 on: April 16, 2017, 09:34:49 AM »
A quick and dirty way to read directly from an offline CSV, without having to code a plugin, could be something simiular to this inline function:
(not tested, might require some fixing, but you get the basic idea...)

Code: [Select]
Public Class VAInline
      Dim table As DataTable

    Public Sub Main()     
        If VA.SessionState.ContainsKey("MyDataTable") Then
            'File has already been read in a previous call, we get the DataTable from the state object
            table = VA.SessionState("MyDataTable")
        Else
            'Read data from the CSV if the table is not already stored in memory
            createDataTable()
        End If

        'Access the data you need from the DataTable object
        '[...]
    End Sub

    Private Sub createDataTable()
            table = New DataTable
            Dim row As DataRow
            Dim totalLines = IO.File.ReadLines("F:\Temp\test.csv")

            Dim header = totalLines.First().Split(","c)
            For i As Integer = 0 To header.Length - 1
                table.Columns.Add(header(i))
            Next

            Dim dataCount As Integer = 1
            Dim data As String()
            Do While dataCount < totalLines.Count
                data = totalLines.Skip(dataCount).First().Split(","c)
                row = table.NewRow()
                For i As Integer = 0 To header.Length - 1
                    row.Item(header(i)) = data(i)
                Next
                table.Rows.Add(row)
                dataCount += 1
            Loop

            VA.SessionState.Add("MyDataTable", table)
    End Sub
End Class
"I am not perfect and neither was my career. In the end tennis is like life, messy."
Marat Safin