sharedStrings.xml and encoding not present in files.
Hi,
So I have a task where I need to keep all the CustomProperties of a file and header's have two values.
Value1\nValue2 where Value1 and Value 2 have to have different fonts.
I managed to do that succesfully but now when I look at the file structure of the xml files it is incorrect and therefore don't pass the necessary checks. For sharedStrings.xml is missing. I found a fix around which is going into the excel sheet and manually saving it with command+S and then they show up but otherwise they dont.
this is my code:
` class TemplateGenerator: def init(self, template_file, name_of_saved_file, data_append=None): self.data_append =data_append self.template_file = template_file self.data_append = data_append self.name_of_saved_file = name_of_saved_file self.alphabet = list(string.ascii_uppercase) self.big = InlineFont(sz=14) self.small = InlineFont(sz=9) self.sheet_counter = 1 self.wb = openpyxl.load_workbook(self.template_file) def generate_sg_template(self):
if self.data_append is not None:
for sheet in self.wb.worksheets:
try:
for data in self.data_append[self.sheet_counter]:
sheet.append(data)
self.sheet_counter +=1
for sheets in self.wb.worksheets:
for row in sheets.iter_rows():
for cell in row:
if cell.internal_value != None:
cell.number_format = numbers.FORMAT_TEXT
except:
print('passing')
pass
for letters in range(len(self.alphabet)):
try:
cell = sheet['{}1'.format(self.alphabet[letters])].value
values = cell.split('\n')
if values[1] != '':
b = TextBlock
first_val = values[0]
second_val = values[1]
rich_string = CellRichText(
b(self.big,first_val + '\n'),
b(self.small, second_val)
)
sheet['{}1'.format(self.alphabet[letters])] = rich_string
except:
pass
print('Done executing file and saving now :)')
#self.wb.save_workbook(self.name_of_saved_file)
save_workbook(self.wb,self.name_of_saved_file)`
this is the difference between template (left) and my output file before manually saving it (right):