Python: Updating Exported Data to Excel (OpenPyXl)
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:
This is what I'd like it to do if it's a new day:
python excel python-3.x for-loop openpyxl
add a comment |
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:
This is what I'd like it to do if it's a new day:
python excel python-3.x for-loop openpyxl
add a comment |
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:
This is what I'd like it to do if it's a new day:
python excel python-3.x for-loop openpyxl
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:
This is what I'd like it to do if it's a new day:
python excel python-3.x for-loop openpyxl
python excel python-3.x for-loop openpyxl
edited Nov 19 at 22:13
grrigore
704820
704820
asked Nov 19 at 21:31
user10676065
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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]
I tried that out and it threw up a bunch of errors.
– user10676065
Nov 20 at 17:01
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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]
I tried that out and it threw up a bunch of errors.
– user10676065
Nov 20 at 17:01
add a comment |
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]
I tried that out and it threw up a bunch of errors.
– user10676065
Nov 20 at 17:01
add a comment |
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]
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]
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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