Python: Updating Exported Data to Excel (OpenPyXl)












0














Nested_Array = [['GOOGL', 9822.6], ['FB', 98.25], ['SPY', 1291]]

now = datetime.datetime.now()
Current_Date = (now.strftime('%Y-%m-%d'))

row_start = 1
col_start = 1

ws4.cell(row=row_start, column=col_start + 1).value = Current_Date

for ticker, profit in (Nested_Array):
ws4.cell(row=row_start + 1, column=col_start).value = ticker
ws4.cell(row=row_start + 1, column=col_start + 1).value = profit
row_start += 1


The screenshot below shows what it exports. However, when I run the program, I'd like it to save the previous days data and then move to a different column for the next day.



If that's possible, I'd like the program to see if it's still the same day when I run it, if it is, it should just update the cells of the days column it's in rather than moving to a new column. Although, if it's not the same day, I'd like it to move to the next day.



Any feedback helps!



This is what it exports currently:



enter image description here



This is what I'd like it to do if it's a new day:



enter image description here










share|improve this question





























    0














    Nested_Array = [['GOOGL', 9822.6], ['FB', 98.25], ['SPY', 1291]]

    now = datetime.datetime.now()
    Current_Date = (now.strftime('%Y-%m-%d'))

    row_start = 1
    col_start = 1

    ws4.cell(row=row_start, column=col_start + 1).value = Current_Date

    for ticker, profit in (Nested_Array):
    ws4.cell(row=row_start + 1, column=col_start).value = ticker
    ws4.cell(row=row_start + 1, column=col_start + 1).value = profit
    row_start += 1


    The screenshot below shows what it exports. However, when I run the program, I'd like it to save the previous days data and then move to a different column for the next day.



    If that's possible, I'd like the program to see if it's still the same day when I run it, if it is, it should just update the cells of the days column it's in rather than moving to a new column. Although, if it's not the same day, I'd like it to move to the next day.



    Any feedback helps!



    This is what it exports currently:



    enter image description here



    This is what I'd like it to do if it's a new day:



    enter image description here










    share|improve this question



























      0












      0








      0







      Nested_Array = [['GOOGL', 9822.6], ['FB', 98.25], ['SPY', 1291]]

      now = datetime.datetime.now()
      Current_Date = (now.strftime('%Y-%m-%d'))

      row_start = 1
      col_start = 1

      ws4.cell(row=row_start, column=col_start + 1).value = Current_Date

      for ticker, profit in (Nested_Array):
      ws4.cell(row=row_start + 1, column=col_start).value = ticker
      ws4.cell(row=row_start + 1, column=col_start + 1).value = profit
      row_start += 1


      The screenshot below shows what it exports. However, when I run the program, I'd like it to save the previous days data and then move to a different column for the next day.



      If that's possible, I'd like the program to see if it's still the same day when I run it, if it is, it should just update the cells of the days column it's in rather than moving to a new column. Although, if it's not the same day, I'd like it to move to the next day.



      Any feedback helps!



      This is what it exports currently:



      enter image description here



      This is what I'd like it to do if it's a new day:



      enter image description here










      share|improve this question















      Nested_Array = [['GOOGL', 9822.6], ['FB', 98.25], ['SPY', 1291]]

      now = datetime.datetime.now()
      Current_Date = (now.strftime('%Y-%m-%d'))

      row_start = 1
      col_start = 1

      ws4.cell(row=row_start, column=col_start + 1).value = Current_Date

      for ticker, profit in (Nested_Array):
      ws4.cell(row=row_start + 1, column=col_start).value = ticker
      ws4.cell(row=row_start + 1, column=col_start + 1).value = profit
      row_start += 1


      The screenshot below shows what it exports. However, when I run the program, I'd like it to save the previous days data and then move to a different column for the next day.



      If that's possible, I'd like the program to see if it's still the same day when I run it, if it is, it should just update the cells of the days column it's in rather than moving to a new column. Although, if it's not the same day, I'd like it to move to the next day.



      Any feedback helps!



      This is what it exports currently:



      enter image description here



      This is what I'd like it to do if it's a new day:



      enter image description here







      python excel python-3.x for-loop openpyxl






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 at 22:13









      grrigore

      704820




      704820










      asked Nov 19 at 21:31







      user10676065































          1 Answer
          1






          active

          oldest

          votes


















          0














          In openpyxl you should generally avoid creating your own counters because it provides useful methods that get this right.



          You can probably do something like this:



          col_idx = ws.max_col + 1
          ws.cell(1, col_idx) = CurrentDate

          for stock, row in zip(NestedArray, ws.iter_cols(min_col=col_idx, max_col=col_idx, min_row=2):
          row[0].value = stock[1]





          share|improve this answer





















          • I tried that out and it threw up a bunch of errors.
            – user10676065
            Nov 20 at 17:01











          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%2f53382935%2fpython-updating-exported-data-to-excel-openpyxl%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









          0














          In openpyxl you should generally avoid creating your own counters because it provides useful methods that get this right.



          You can probably do something like this:



          col_idx = ws.max_col + 1
          ws.cell(1, col_idx) = CurrentDate

          for stock, row in zip(NestedArray, ws.iter_cols(min_col=col_idx, max_col=col_idx, min_row=2):
          row[0].value = stock[1]





          share|improve this answer





















          • I tried that out and it threw up a bunch of errors.
            – user10676065
            Nov 20 at 17:01
















          0














          In openpyxl you should generally avoid creating your own counters because it provides useful methods that get this right.



          You can probably do something like this:



          col_idx = ws.max_col + 1
          ws.cell(1, col_idx) = CurrentDate

          for stock, row in zip(NestedArray, ws.iter_cols(min_col=col_idx, max_col=col_idx, min_row=2):
          row[0].value = stock[1]





          share|improve this answer





















          • I tried that out and it threw up a bunch of errors.
            – user10676065
            Nov 20 at 17:01














          0












          0








          0






          In openpyxl you should generally avoid creating your own counters because it provides useful methods that get this right.



          You can probably do something like this:



          col_idx = ws.max_col + 1
          ws.cell(1, col_idx) = CurrentDate

          for stock, row in zip(NestedArray, ws.iter_cols(min_col=col_idx, max_col=col_idx, min_row=2):
          row[0].value = stock[1]





          share|improve this answer












          In openpyxl you should generally avoid creating your own counters because it provides useful methods that get this right.



          You can probably do something like this:



          col_idx = ws.max_col + 1
          ws.cell(1, col_idx) = CurrentDate

          for stock, row in zip(NestedArray, ws.iter_cols(min_col=col_idx, max_col=col_idx, min_row=2):
          row[0].value = stock[1]






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 9:20









          Charlie Clark

          9,64622233




          9,64622233












          • I tried that out and it threw up a bunch of errors.
            – user10676065
            Nov 20 at 17:01


















          • I tried that out and it threw up a bunch of errors.
            – user10676065
            Nov 20 at 17:01
















          I tried that out and it threw up a bunch of errors.
          – user10676065
          Nov 20 at 17:01




          I tried that out and it threw up a bunch of errors.
          – user10676065
          Nov 20 at 17:01


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53382935%2fpython-updating-exported-data-to-excel-openpyxl%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

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy