Home > database >  Quotation issues while writing formulas in xlsxwriter
Quotation issues while writing formulas in xlsxwriter

Time:06-28

I need to write SUMIFS formulas in Excel using xlsxwriter. I think this may be more of a quotations in strings question but I'm not sure.

Example

=SUMIFS('datasheet'!N:N,'datasheet'!D:D,'Sch B'!B:B,'datasheet'!J:J,"G")

I took the documentation code and added the example SUMIFS formula on line23. It gets wonky at "G".

Documentation Code

import xlsxwriter

# Create a workbook and add a worksheet.
workbook = xlsxwriter.Workbook('output.xlsx')
worksheet = workbook.add_worksheet()

# Some data we want to write to the worksheet.
expenses = (
    ['Rent', 1000],
    ['Gas', 100],
    ['Food', 300],
    ['Gym', 50],
)

# Start from the first cell. Rows and columns are zero indexed.
row = 0
col = 0

# Iterate over the data and write it out row by row.
for item, cost in expenses:
    worksheet.write(row, col, item)
    worksheet.write(row, col   1, cost)
    worksheet.write_formula(row, col   2, "=SUMIFS('datasheet'!N:N,'datasheet'!D:D,'Sch B '!B:B,'datasheet'!J:J,"G")")
    row  = 1


workbook.close()

Thank you!

CodePudding user response:

The solution is a string based solution. Adding \" in front of the quotation to protect it. =SUMIFS('datasheet'!N:N,'datasheet'!D:D,'Sch B'!B:B,'datasheet'!J:J,\"G\")

  • Related