Xlsxwriter - Dynamically change the formatting based on column label





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















I am trying to define the formatting that needs to be applied to each column of an excel spreadsheet based on the column name.



For example, if column name is 'count' then 'number_format' needs to be used. If column name is 'sale_date' then 'date_format' needs to be used.



number_format = workbook.add_format({'num_format': '0', 'font_size': 12})
date_format = workbook.add_format({'num_format': 'dd/mm/yyyy hh:mm:ss', 'font_size': 12})


Using the above two formats in the respective columns as shown below:



worksheet1.write('A1', 'count', number_format)
worksheet1.write('B1', 'sale_date', date_format)


Could I make this dynamic based on the column name instead of defining format by column label. Thanks



Update:



Loop that displays the header column in the excel spreadsheet



for data in title:
worksheet.write(row, col, data, number_format)
col += 1









share|improve this question































    2















    I am trying to define the formatting that needs to be applied to each column of an excel spreadsheet based on the column name.



    For example, if column name is 'count' then 'number_format' needs to be used. If column name is 'sale_date' then 'date_format' needs to be used.



    number_format = workbook.add_format({'num_format': '0', 'font_size': 12})
    date_format = workbook.add_format({'num_format': 'dd/mm/yyyy hh:mm:ss', 'font_size': 12})


    Using the above two formats in the respective columns as shown below:



    worksheet1.write('A1', 'count', number_format)
    worksheet1.write('B1', 'sale_date', date_format)


    Could I make this dynamic based on the column name instead of defining format by column label. Thanks



    Update:



    Loop that displays the header column in the excel spreadsheet



    for data in title:
    worksheet.write(row, col, data, number_format)
    col += 1









    share|improve this question



























      2












      2








      2








      I am trying to define the formatting that needs to be applied to each column of an excel spreadsheet based on the column name.



      For example, if column name is 'count' then 'number_format' needs to be used. If column name is 'sale_date' then 'date_format' needs to be used.



      number_format = workbook.add_format({'num_format': '0', 'font_size': 12})
      date_format = workbook.add_format({'num_format': 'dd/mm/yyyy hh:mm:ss', 'font_size': 12})


      Using the above two formats in the respective columns as shown below:



      worksheet1.write('A1', 'count', number_format)
      worksheet1.write('B1', 'sale_date', date_format)


      Could I make this dynamic based on the column name instead of defining format by column label. Thanks



      Update:



      Loop that displays the header column in the excel spreadsheet



      for data in title:
      worksheet.write(row, col, data, number_format)
      col += 1









      share|improve this question
















      I am trying to define the formatting that needs to be applied to each column of an excel spreadsheet based on the column name.



      For example, if column name is 'count' then 'number_format' needs to be used. If column name is 'sale_date' then 'date_format' needs to be used.



      number_format = workbook.add_format({'num_format': '0', 'font_size': 12})
      date_format = workbook.add_format({'num_format': 'dd/mm/yyyy hh:mm:ss', 'font_size': 12})


      Using the above two formats in the respective columns as shown below:



      worksheet1.write('A1', 'count', number_format)
      worksheet1.write('B1', 'sale_date', date_format)


      Could I make this dynamic based on the column name instead of defining format by column label. Thanks



      Update:



      Loop that displays the header column in the excel spreadsheet



      for data in title:
      worksheet.write(row, col, data, number_format)
      col += 1






      python xlsxwriter






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 9:16







      dark horse

















      asked Nov 23 '18 at 6:27









      dark horsedark horse

      16210




      16210
























          1 Answer
          1






          active

          oldest

          votes


















          2















          Comment: date_format = workbook.add_format({'num_format': 'dd/mm/yy'}), shows the date column as unix number rather than a proper date.

          Sample value shown is : 42668 instead of displaying "24-10-16".




          This is default behavior defined by Windows Excel.

          Read Excel for Windows stores dates by default as the number of days

          Documentation: XlsxWriter Working with Dates and Time






          Comment: ...that I could use the appropriate format based on column name (namely count, sale_date)




          You can use worksheet.set_column() to set a Style for a whole Column.

          Documentation: XlsxWriter worksheet.set_column()



          Precondition: The Order of the Columns Name/Style must be in sync with your table.

          E.g. count == 'A', sale_date == 'B' and so on...



          from collections import OrderedDict

          _styles = OrderedDict([('count',number_format), ('sale_date', date_format), ('total', number_format), ('text', string_format)])

          for col, key in enumerate(_styles):
          A1_notation = '{c}:{c}'.format(c=chr(col + 65))
          worksheet.set_column(A1_notation, None, _styles[key])
          print("worksheet.set_column('{}', None, {})".format(A1_notation, _styles[key]))



          Output:



          worksheet.set_column('A:A', None, number_format)
          worksheet.set_column('B:B', None, date_format)
          worksheet.set_column('C:C', None, number_format)
          worksheet.set_column('D:D', None, string_format)



          For subsequent writes you don't need to assign a style, e.g. use



          worksheet.write('A1', 123)  


          will default to A:A number_format






          Question: Could I make this dynamic based on the column name




          You are not using "column name", it's called Cell A1 Notation.

          Setup a mapping dict, for example:



          style_map = {'A': number_format, 'B':date_format}



          Usage:
          Note: This will only work with single letter, from A to Z




          def write(A1_notation, value):
          worksheet1.write(A1_notation, value, style_map[A1_notation[0]])




          For Row-column notation (0, 0):



          style_map = {'0': number_format, '1':date_format}



          Usage:




          def write(row, col, value):
          worksheet1.write(row, col, value, style_map[col])

          from xlsxwriter.utility import xl_rowcol_to_cell

          def write(A1_notation, value):
          worksheet1.write(A1_notation, value, style_map[xl_cell_to_rowcol(A1_notation)[1]])





          share|improve this answer


























          • thanks for your reply.. Just to make sure I got this right, we are first creating a dictionary of 2 pairs (one for number_format and the other for date_format).. We then use "worksheet1.write(row, col, value, style_map[col])" to define the formatting by column.. Is my understanding right, thanks..

            – dark horse
            Nov 23 '18 at 8:56













          • "2 pairs (one for number_format and the other for date_format)": Not only how many unique styles, there must be a dict key for every Column.

            – stovfl
            Nov 23 '18 at 9:12











          • thanks for the reply. Just one more query I had was I have included the "for loop" that displays the column names in the excel spreadsheet as part of my initial post. Could you please advice how i could have this modified such that I could use the appropriate format based on column name (namely count, sale_date).. Thanks..

            – dark horse
            Nov 23 '18 at 9:19











          • thanks for your update.. One problem I am having is I trying to convert date columns in this format "date_format = workbook.add_format({'num_format': 'dd/mm/yy'})" .. This however shows the date column as unix number rather than a proper date.Sample value shown is : 42668 instead of displaying "24-10-16"

            – dark horse
            Nov 23 '18 at 12:08











          • sorry for not accepting your answer earlier.. I was trying to check if you could help me with this other problem as well.. I was trying to see how we could display the actual date and not just the unix date format.

            – dark horse
            Nov 23 '18 at 12:56












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441573%2fxlsxwriter-dynamically-change-the-formatting-based-on-column-label%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2















          Comment: date_format = workbook.add_format({'num_format': 'dd/mm/yy'}), shows the date column as unix number rather than a proper date.

          Sample value shown is : 42668 instead of displaying "24-10-16".




          This is default behavior defined by Windows Excel.

          Read Excel for Windows stores dates by default as the number of days

          Documentation: XlsxWriter Working with Dates and Time






          Comment: ...that I could use the appropriate format based on column name (namely count, sale_date)




          You can use worksheet.set_column() to set a Style for a whole Column.

          Documentation: XlsxWriter worksheet.set_column()



          Precondition: The Order of the Columns Name/Style must be in sync with your table.

          E.g. count == 'A', sale_date == 'B' and so on...



          from collections import OrderedDict

          _styles = OrderedDict([('count',number_format), ('sale_date', date_format), ('total', number_format), ('text', string_format)])

          for col, key in enumerate(_styles):
          A1_notation = '{c}:{c}'.format(c=chr(col + 65))
          worksheet.set_column(A1_notation, None, _styles[key])
          print("worksheet.set_column('{}', None, {})".format(A1_notation, _styles[key]))



          Output:



          worksheet.set_column('A:A', None, number_format)
          worksheet.set_column('B:B', None, date_format)
          worksheet.set_column('C:C', None, number_format)
          worksheet.set_column('D:D', None, string_format)



          For subsequent writes you don't need to assign a style, e.g. use



          worksheet.write('A1', 123)  


          will default to A:A number_format






          Question: Could I make this dynamic based on the column name




          You are not using "column name", it's called Cell A1 Notation.

          Setup a mapping dict, for example:



          style_map = {'A': number_format, 'B':date_format}



          Usage:
          Note: This will only work with single letter, from A to Z




          def write(A1_notation, value):
          worksheet1.write(A1_notation, value, style_map[A1_notation[0]])




          For Row-column notation (0, 0):



          style_map = {'0': number_format, '1':date_format}



          Usage:




          def write(row, col, value):
          worksheet1.write(row, col, value, style_map[col])

          from xlsxwriter.utility import xl_rowcol_to_cell

          def write(A1_notation, value):
          worksheet1.write(A1_notation, value, style_map[xl_cell_to_rowcol(A1_notation)[1]])





          share|improve this answer


























          • thanks for your reply.. Just to make sure I got this right, we are first creating a dictionary of 2 pairs (one for number_format and the other for date_format).. We then use "worksheet1.write(row, col, value, style_map[col])" to define the formatting by column.. Is my understanding right, thanks..

            – dark horse
            Nov 23 '18 at 8:56













          • "2 pairs (one for number_format and the other for date_format)": Not only how many unique styles, there must be a dict key for every Column.

            – stovfl
            Nov 23 '18 at 9:12











          • thanks for the reply. Just one more query I had was I have included the "for loop" that displays the column names in the excel spreadsheet as part of my initial post. Could you please advice how i could have this modified such that I could use the appropriate format based on column name (namely count, sale_date).. Thanks..

            – dark horse
            Nov 23 '18 at 9:19











          • thanks for your update.. One problem I am having is I trying to convert date columns in this format "date_format = workbook.add_format({'num_format': 'dd/mm/yy'})" .. This however shows the date column as unix number rather than a proper date.Sample value shown is : 42668 instead of displaying "24-10-16"

            – dark horse
            Nov 23 '18 at 12:08











          • sorry for not accepting your answer earlier.. I was trying to check if you could help me with this other problem as well.. I was trying to see how we could display the actual date and not just the unix date format.

            – dark horse
            Nov 23 '18 at 12:56
















          2















          Comment: date_format = workbook.add_format({'num_format': 'dd/mm/yy'}), shows the date column as unix number rather than a proper date.

          Sample value shown is : 42668 instead of displaying "24-10-16".




          This is default behavior defined by Windows Excel.

          Read Excel for Windows stores dates by default as the number of days

          Documentation: XlsxWriter Working with Dates and Time






          Comment: ...that I could use the appropriate format based on column name (namely count, sale_date)




          You can use worksheet.set_column() to set a Style for a whole Column.

          Documentation: XlsxWriter worksheet.set_column()



          Precondition: The Order of the Columns Name/Style must be in sync with your table.

          E.g. count == 'A', sale_date == 'B' and so on...



          from collections import OrderedDict

          _styles = OrderedDict([('count',number_format), ('sale_date', date_format), ('total', number_format), ('text', string_format)])

          for col, key in enumerate(_styles):
          A1_notation = '{c}:{c}'.format(c=chr(col + 65))
          worksheet.set_column(A1_notation, None, _styles[key])
          print("worksheet.set_column('{}', None, {})".format(A1_notation, _styles[key]))



          Output:



          worksheet.set_column('A:A', None, number_format)
          worksheet.set_column('B:B', None, date_format)
          worksheet.set_column('C:C', None, number_format)
          worksheet.set_column('D:D', None, string_format)



          For subsequent writes you don't need to assign a style, e.g. use



          worksheet.write('A1', 123)  


          will default to A:A number_format






          Question: Could I make this dynamic based on the column name




          You are not using "column name", it's called Cell A1 Notation.

          Setup a mapping dict, for example:



          style_map = {'A': number_format, 'B':date_format}



          Usage:
          Note: This will only work with single letter, from A to Z




          def write(A1_notation, value):
          worksheet1.write(A1_notation, value, style_map[A1_notation[0]])




          For Row-column notation (0, 0):



          style_map = {'0': number_format, '1':date_format}



          Usage:




          def write(row, col, value):
          worksheet1.write(row, col, value, style_map[col])

          from xlsxwriter.utility import xl_rowcol_to_cell

          def write(A1_notation, value):
          worksheet1.write(A1_notation, value, style_map[xl_cell_to_rowcol(A1_notation)[1]])





          share|improve this answer


























          • thanks for your reply.. Just to make sure I got this right, we are first creating a dictionary of 2 pairs (one for number_format and the other for date_format).. We then use "worksheet1.write(row, col, value, style_map[col])" to define the formatting by column.. Is my understanding right, thanks..

            – dark horse
            Nov 23 '18 at 8:56













          • "2 pairs (one for number_format and the other for date_format)": Not only how many unique styles, there must be a dict key for every Column.

            – stovfl
            Nov 23 '18 at 9:12











          • thanks for the reply. Just one more query I had was I have included the "for loop" that displays the column names in the excel spreadsheet as part of my initial post. Could you please advice how i could have this modified such that I could use the appropriate format based on column name (namely count, sale_date).. Thanks..

            – dark horse
            Nov 23 '18 at 9:19











          • thanks for your update.. One problem I am having is I trying to convert date columns in this format "date_format = workbook.add_format({'num_format': 'dd/mm/yy'})" .. This however shows the date column as unix number rather than a proper date.Sample value shown is : 42668 instead of displaying "24-10-16"

            – dark horse
            Nov 23 '18 at 12:08











          • sorry for not accepting your answer earlier.. I was trying to check if you could help me with this other problem as well.. I was trying to see how we could display the actual date and not just the unix date format.

            – dark horse
            Nov 23 '18 at 12:56














          2












          2








          2








          Comment: date_format = workbook.add_format({'num_format': 'dd/mm/yy'}), shows the date column as unix number rather than a proper date.

          Sample value shown is : 42668 instead of displaying "24-10-16".




          This is default behavior defined by Windows Excel.

          Read Excel for Windows stores dates by default as the number of days

          Documentation: XlsxWriter Working with Dates and Time






          Comment: ...that I could use the appropriate format based on column name (namely count, sale_date)




          You can use worksheet.set_column() to set a Style for a whole Column.

          Documentation: XlsxWriter worksheet.set_column()



          Precondition: The Order of the Columns Name/Style must be in sync with your table.

          E.g. count == 'A', sale_date == 'B' and so on...



          from collections import OrderedDict

          _styles = OrderedDict([('count',number_format), ('sale_date', date_format), ('total', number_format), ('text', string_format)])

          for col, key in enumerate(_styles):
          A1_notation = '{c}:{c}'.format(c=chr(col + 65))
          worksheet.set_column(A1_notation, None, _styles[key])
          print("worksheet.set_column('{}', None, {})".format(A1_notation, _styles[key]))



          Output:



          worksheet.set_column('A:A', None, number_format)
          worksheet.set_column('B:B', None, date_format)
          worksheet.set_column('C:C', None, number_format)
          worksheet.set_column('D:D', None, string_format)



          For subsequent writes you don't need to assign a style, e.g. use



          worksheet.write('A1', 123)  


          will default to A:A number_format






          Question: Could I make this dynamic based on the column name




          You are not using "column name", it's called Cell A1 Notation.

          Setup a mapping dict, for example:



          style_map = {'A': number_format, 'B':date_format}



          Usage:
          Note: This will only work with single letter, from A to Z




          def write(A1_notation, value):
          worksheet1.write(A1_notation, value, style_map[A1_notation[0]])




          For Row-column notation (0, 0):



          style_map = {'0': number_format, '1':date_format}



          Usage:




          def write(row, col, value):
          worksheet1.write(row, col, value, style_map[col])

          from xlsxwriter.utility import xl_rowcol_to_cell

          def write(A1_notation, value):
          worksheet1.write(A1_notation, value, style_map[xl_cell_to_rowcol(A1_notation)[1]])





          share|improve this answer
















          Comment: date_format = workbook.add_format({'num_format': 'dd/mm/yy'}), shows the date column as unix number rather than a proper date.

          Sample value shown is : 42668 instead of displaying "24-10-16".




          This is default behavior defined by Windows Excel.

          Read Excel for Windows stores dates by default as the number of days

          Documentation: XlsxWriter Working with Dates and Time






          Comment: ...that I could use the appropriate format based on column name (namely count, sale_date)




          You can use worksheet.set_column() to set a Style for a whole Column.

          Documentation: XlsxWriter worksheet.set_column()



          Precondition: The Order of the Columns Name/Style must be in sync with your table.

          E.g. count == 'A', sale_date == 'B' and so on...



          from collections import OrderedDict

          _styles = OrderedDict([('count',number_format), ('sale_date', date_format), ('total', number_format), ('text', string_format)])

          for col, key in enumerate(_styles):
          A1_notation = '{c}:{c}'.format(c=chr(col + 65))
          worksheet.set_column(A1_notation, None, _styles[key])
          print("worksheet.set_column('{}', None, {})".format(A1_notation, _styles[key]))



          Output:



          worksheet.set_column('A:A', None, number_format)
          worksheet.set_column('B:B', None, date_format)
          worksheet.set_column('C:C', None, number_format)
          worksheet.set_column('D:D', None, string_format)



          For subsequent writes you don't need to assign a style, e.g. use



          worksheet.write('A1', 123)  


          will default to A:A number_format






          Question: Could I make this dynamic based on the column name




          You are not using "column name", it's called Cell A1 Notation.

          Setup a mapping dict, for example:



          style_map = {'A': number_format, 'B':date_format}



          Usage:
          Note: This will only work with single letter, from A to Z




          def write(A1_notation, value):
          worksheet1.write(A1_notation, value, style_map[A1_notation[0]])




          For Row-column notation (0, 0):



          style_map = {'0': number_format, '1':date_format}



          Usage:




          def write(row, col, value):
          worksheet1.write(row, col, value, style_map[col])

          from xlsxwriter.utility import xl_rowcol_to_cell

          def write(A1_notation, value):
          worksheet1.write(A1_notation, value, style_map[xl_cell_to_rowcol(A1_notation)[1]])






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 23 '18 at 13:12

























          answered Nov 23 '18 at 8:39









          stovflstovfl

          8,51251134




          8,51251134













          • thanks for your reply.. Just to make sure I got this right, we are first creating a dictionary of 2 pairs (one for number_format and the other for date_format).. We then use "worksheet1.write(row, col, value, style_map[col])" to define the formatting by column.. Is my understanding right, thanks..

            – dark horse
            Nov 23 '18 at 8:56













          • "2 pairs (one for number_format and the other for date_format)": Not only how many unique styles, there must be a dict key for every Column.

            – stovfl
            Nov 23 '18 at 9:12











          • thanks for the reply. Just one more query I had was I have included the "for loop" that displays the column names in the excel spreadsheet as part of my initial post. Could you please advice how i could have this modified such that I could use the appropriate format based on column name (namely count, sale_date).. Thanks..

            – dark horse
            Nov 23 '18 at 9:19











          • thanks for your update.. One problem I am having is I trying to convert date columns in this format "date_format = workbook.add_format({'num_format': 'dd/mm/yy'})" .. This however shows the date column as unix number rather than a proper date.Sample value shown is : 42668 instead of displaying "24-10-16"

            – dark horse
            Nov 23 '18 at 12:08











          • sorry for not accepting your answer earlier.. I was trying to check if you could help me with this other problem as well.. I was trying to see how we could display the actual date and not just the unix date format.

            – dark horse
            Nov 23 '18 at 12:56



















          • thanks for your reply.. Just to make sure I got this right, we are first creating a dictionary of 2 pairs (one for number_format and the other for date_format).. We then use "worksheet1.write(row, col, value, style_map[col])" to define the formatting by column.. Is my understanding right, thanks..

            – dark horse
            Nov 23 '18 at 8:56













          • "2 pairs (one for number_format and the other for date_format)": Not only how many unique styles, there must be a dict key for every Column.

            – stovfl
            Nov 23 '18 at 9:12











          • thanks for the reply. Just one more query I had was I have included the "for loop" that displays the column names in the excel spreadsheet as part of my initial post. Could you please advice how i could have this modified such that I could use the appropriate format based on column name (namely count, sale_date).. Thanks..

            – dark horse
            Nov 23 '18 at 9:19











          • thanks for your update.. One problem I am having is I trying to convert date columns in this format "date_format = workbook.add_format({'num_format': 'dd/mm/yy'})" .. This however shows the date column as unix number rather than a proper date.Sample value shown is : 42668 instead of displaying "24-10-16"

            – dark horse
            Nov 23 '18 at 12:08











          • sorry for not accepting your answer earlier.. I was trying to check if you could help me with this other problem as well.. I was trying to see how we could display the actual date and not just the unix date format.

            – dark horse
            Nov 23 '18 at 12:56

















          thanks for your reply.. Just to make sure I got this right, we are first creating a dictionary of 2 pairs (one for number_format and the other for date_format).. We then use "worksheet1.write(row, col, value, style_map[col])" to define the formatting by column.. Is my understanding right, thanks..

          – dark horse
          Nov 23 '18 at 8:56







          thanks for your reply.. Just to make sure I got this right, we are first creating a dictionary of 2 pairs (one for number_format and the other for date_format).. We then use "worksheet1.write(row, col, value, style_map[col])" to define the formatting by column.. Is my understanding right, thanks..

          – dark horse
          Nov 23 '18 at 8:56















          "2 pairs (one for number_format and the other for date_format)": Not only how many unique styles, there must be a dict key for every Column.

          – stovfl
          Nov 23 '18 at 9:12





          "2 pairs (one for number_format and the other for date_format)": Not only how many unique styles, there must be a dict key for every Column.

          – stovfl
          Nov 23 '18 at 9:12













          thanks for the reply. Just one more query I had was I have included the "for loop" that displays the column names in the excel spreadsheet as part of my initial post. Could you please advice how i could have this modified such that I could use the appropriate format based on column name (namely count, sale_date).. Thanks..

          – dark horse
          Nov 23 '18 at 9:19





          thanks for the reply. Just one more query I had was I have included the "for loop" that displays the column names in the excel spreadsheet as part of my initial post. Could you please advice how i could have this modified such that I could use the appropriate format based on column name (namely count, sale_date).. Thanks..

          – dark horse
          Nov 23 '18 at 9:19













          thanks for your update.. One problem I am having is I trying to convert date columns in this format "date_format = workbook.add_format({'num_format': 'dd/mm/yy'})" .. This however shows the date column as unix number rather than a proper date.Sample value shown is : 42668 instead of displaying "24-10-16"

          – dark horse
          Nov 23 '18 at 12:08





          thanks for your update.. One problem I am having is I trying to convert date columns in this format "date_format = workbook.add_format({'num_format': 'dd/mm/yy'})" .. This however shows the date column as unix number rather than a proper date.Sample value shown is : 42668 instead of displaying "24-10-16"

          – dark horse
          Nov 23 '18 at 12:08













          sorry for not accepting your answer earlier.. I was trying to check if you could help me with this other problem as well.. I was trying to see how we could display the actual date and not just the unix date format.

          – dark horse
          Nov 23 '18 at 12:56





          sorry for not accepting your answer earlier.. I was trying to check if you could help me with this other problem as well.. I was trying to see how we could display the actual date and not just the unix date format.

          – dark horse
          Nov 23 '18 at 12:56




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441573%2fxlsxwriter-dynamically-change-the-formatting-based-on-column-label%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

          ComboBox Display Member on multiple fields

          Is it possible to collect Nectar points via Trainline?