0

I have an Excel spreadsheet on which I run macros to generate a json file, which I include in my project in the raw folder for further use within the app. But this produces an overhead of exporting an Excel file with the project.

I was wondering if it was somehow possible to include a csv file within the project and run the macro code (or some other code) on it in runtime to get the json string?

halfer
  • 18,701
  • 13
  • 79
  • 158
Shubham
  • 155
  • 2
  • 11
  • Please, explain in more detail. What are you doing exactly? – Peter Aug 16 '19 at 10:09
  • @Peter I am creating a survey app, where all the metadata like questions, options are present in a list form in an excel spreadsheet. Creating everything in strings.xml would've required a lot of manual work so I wrote a macro to convert it into a json array and output a .json file, which I import in my resources -> raw folder and then parse using native JSON helper methods of android to create POJO classes. If later one decides to make changes to the survey you can either edit excel, or directly edit the json file which in case of large changes, defeats the purpose. – Shubham Aug 16 '19 at 10:42
  • Ok,.. but I don't understand the problem. Write a Java/Kotlin/Groovy/JS/... method and execute it. Could be a test case, a java main method ... You can trigger that piece of code via a gradle task for instant. What is the purpose of doing this at runtime? Would the parsing stuff happen when the user opens the mobile app? Before or at compile time is faster, isn't it? – Peter Aug 16 '19 at 11:33
  • Oh yes, my bad. I meant compile time indeed and not runtime. But yes, that's exactly what I don't know how to do. A Java main method taking csv as input and processing it to produce string output. In that case macro won't be needed. – Shubham Aug 16 '19 at 11:45

1 Answers1

1

Here's a question on Read CSV with Scanner().

You find an executable java main method in the first answer. This may be a good starting point for you.

Peter
  • 4,039
  • 1
  • 16
  • 27