This example is good, but there is a problem because it is in series. And I don’t want to do a series, I want something like this:
example 1
import json
def save_to_dict():
doc = XSCRIPTCONTEXT.getDocument()
columnsCells = ["A1", "B4"] # range all columns and cells
for x in columnsCells:
data = doc.CurrentController.ActiveSheet[x[0]+x[1].DataArray
with open('test.json','w') as jsonfile:
json.dump( dict(data), jsonfile )
describe: in this small change, I can automatically add a series from A1 to B4. But I can also generate a for that generates these automatic indexes. It’s not so good my example, but it’s something I’m thinking folks.
example 2
import json
def save_to_dict():
doc = XSCRIPTCONTEXT.getDocument()
allColumnsCells = [list(range(1, 100))] # range all columns and cells
for x in allColumnsCells:
data = doc.CurrentController.ActiveSheet[x].DataArray
with open('test.json','w') as jsonfile:
json.dump( dict(data), jsonfile )
problem
my problem is that I have to know how many rows and columns there are, if I know how many rows and columns there are, the next step is to read the rows and columns, after that the next step is to generate the json file with this information
if I need to export that’s it, this is the sequence of steps,
if i need to read the file i would have to read it in json format and specify to the program to write this information in the new odt file with the rows and columns again
example 3
import json
def settingsFileUser():
addFilepathODT = input("add filepath odt: ") # C:\Users\username\folderName\calc.json
importFileJsonCalc(addFilepathODT ) # C:\Users\username\folderName\calc.json =: C:\Users\username\folderName\new_file_calc.odt
save_to_dic_export_jsonCalc(addFilepathODT ) # C:\Users\username\folderName\calc.json
def save_to_dic_export_jsonCalc(addFilepathODT ):
doc = XSCRIPTCONTEXT.getDocument()
for sheet in doc.Sheets:
allColumnsCells = [list(range(sheet.Column, sheet.Row))] # range all columns and cells
for x in allColumnsCells:
data = doc.CurrentController.ActiveSheet[x].DataArray
sheetFileName = doc.getCurrentController().getActiveSheet()
with open(sheetFileName+'.json','w') as jsonfile:
json.dump( dict(data), jsonfile )
def importFileJsonCalc(): # read the file in json and create the corresponding odt file.
doc = XSCRIPTCONTEXT.getDocument()
for sheet in doc.Sheets:
allColumnsCells = [list(range(sheet.Column, sheet.Row))] # range all columns and cells
for x in allColumnsCells:
data = doc.CurrentController.ActiveSheet[x].DataArray
sheetFileName = doc.getCurrentController().getActiveSheet()
with open(sheetFileName+'.json','w') as jsonfile:
json.dump( dict(data), jsonfile )
with open(sheetFileName+'.odt','w') as jsonfile:
json.dump( dict(data), jsonfile )
refs