Python: Append a row to the end of an (.xlsx) document
Objective:
Appending a row to an (.xlsx) document using python (3.7).
What I wish to append to the last row of Document.xlsx. (cell delimiter: " | "):
(Last_Row): [Tom] | [Tablet] | [003332] | [Returned] | [PSEA]
Document.xlsx:
[ A ] | [ B ] | [ C ] | [ D ] | [ E ]
1: [FIID:] | [Device:] | [Gov_ID:] | [ Status ] | [Project:]
2: [John ] | [Laptop ] | [002435 ] | [Resigned] | [ AWSD ]
...
+4,000 rows
What I have so far is appending from a (.csv) document.
Pulling_Data_CSV.py
import csv
df = pd.read_csv(r"C:...Test_Pandas.csv")
with open(r"C:...Test_Pandas.csv", "a",newline="") as
csvfile:
writer = csv.writer(csvfile)
writer.writerow(["Tom", "Laptop", "003332", "Returned", "AWSD"])
What is the equivalent for editing a (.xlsx) document?
If that is not possible, how would I convert a (.xlsx) to (.csv), append a row, then convert it back to a (.xlsx) document?
python excel pandas csv openxlsx
add a comment |
Objective:
Appending a row to an (.xlsx) document using python (3.7).
What I wish to append to the last row of Document.xlsx. (cell delimiter: " | "):
(Last_Row): [Tom] | [Tablet] | [003332] | [Returned] | [PSEA]
Document.xlsx:
[ A ] | [ B ] | [ C ] | [ D ] | [ E ]
1: [FIID:] | [Device:] | [Gov_ID:] | [ Status ] | [Project:]
2: [John ] | [Laptop ] | [002435 ] | [Resigned] | [ AWSD ]
...
+4,000 rows
What I have so far is appending from a (.csv) document.
Pulling_Data_CSV.py
import csv
df = pd.read_csv(r"C:...Test_Pandas.csv")
with open(r"C:...Test_Pandas.csv", "a",newline="") as
csvfile:
writer = csv.writer(csvfile)
writer.writerow(["Tom", "Laptop", "003332", "Returned", "AWSD"])
What is the equivalent for editing a (.xlsx) document?
If that is not possible, how would I convert a (.xlsx) to (.csv), append a row, then convert it back to a (.xlsx) document?
python excel pandas csv openxlsx
add a comment |
Objective:
Appending a row to an (.xlsx) document using python (3.7).
What I wish to append to the last row of Document.xlsx. (cell delimiter: " | "):
(Last_Row): [Tom] | [Tablet] | [003332] | [Returned] | [PSEA]
Document.xlsx:
[ A ] | [ B ] | [ C ] | [ D ] | [ E ]
1: [FIID:] | [Device:] | [Gov_ID:] | [ Status ] | [Project:]
2: [John ] | [Laptop ] | [002435 ] | [Resigned] | [ AWSD ]
...
+4,000 rows
What I have so far is appending from a (.csv) document.
Pulling_Data_CSV.py
import csv
df = pd.read_csv(r"C:...Test_Pandas.csv")
with open(r"C:...Test_Pandas.csv", "a",newline="") as
csvfile:
writer = csv.writer(csvfile)
writer.writerow(["Tom", "Laptop", "003332", "Returned", "AWSD"])
What is the equivalent for editing a (.xlsx) document?
If that is not possible, how would I convert a (.xlsx) to (.csv), append a row, then convert it back to a (.xlsx) document?
python excel pandas csv openxlsx
Objective:
Appending a row to an (.xlsx) document using python (3.7).
What I wish to append to the last row of Document.xlsx. (cell delimiter: " | "):
(Last_Row): [Tom] | [Tablet] | [003332] | [Returned] | [PSEA]
Document.xlsx:
[ A ] | [ B ] | [ C ] | [ D ] | [ E ]
1: [FIID:] | [Device:] | [Gov_ID:] | [ Status ] | [Project:]
2: [John ] | [Laptop ] | [002435 ] | [Resigned] | [ AWSD ]
...
+4,000 rows
What I have so far is appending from a (.csv) document.
Pulling_Data_CSV.py
import csv
df = pd.read_csv(r"C:...Test_Pandas.csv")
with open(r"C:...Test_Pandas.csv", "a",newline="") as
csvfile:
writer = csv.writer(csvfile)
writer.writerow(["Tom", "Laptop", "003332", "Returned", "AWSD"])
What is the equivalent for editing a (.xlsx) document?
If that is not possible, how would I convert a (.xlsx) to (.csv), append a row, then convert it back to a (.xlsx) document?
python excel pandas csv openxlsx
python excel pandas csv openxlsx
edited Nov 13 '18 at 15:45
Quantum Nebula
asked Nov 13 '18 at 15:43
Quantum NebulaQuantum Nebula
53
53
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Here's an example using openpyxl:
import openpyxl
filename = 'C:\temp\spreadsheet.xlsx'
wb = openpyxl.load_workbook(filename=filename)
sheet = wb['Sheet1']
new_row = ['column1', 'column2', 'column3']
sheet.append(new_row)
wb.save(filename)
1
Works flawlessly! Thank you! Now I got to add a border to the appended row, but I can look that up in the documentation for openpyxl
– Quantum Nebula
Nov 13 '18 at 16:14
add a comment |
xlsx is a complex container format, based on xml. You could parse that yourself, but likely you want to check out a module like openpyxl and go from there.
Looking up the documentation for openpyxl, thank you. pointed me into the right direction.
– Quantum Nebula
Nov 13 '18 at 16:19
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%2f53284571%2fpython-append-a-row-to-the-end-of-an-xlsx-document%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here's an example using openpyxl:
import openpyxl
filename = 'C:\temp\spreadsheet.xlsx'
wb = openpyxl.load_workbook(filename=filename)
sheet = wb['Sheet1']
new_row = ['column1', 'column2', 'column3']
sheet.append(new_row)
wb.save(filename)
1
Works flawlessly! Thank you! Now I got to add a border to the appended row, but I can look that up in the documentation for openpyxl
– Quantum Nebula
Nov 13 '18 at 16:14
add a comment |
Here's an example using openpyxl:
import openpyxl
filename = 'C:\temp\spreadsheet.xlsx'
wb = openpyxl.load_workbook(filename=filename)
sheet = wb['Sheet1']
new_row = ['column1', 'column2', 'column3']
sheet.append(new_row)
wb.save(filename)
1
Works flawlessly! Thank you! Now I got to add a border to the appended row, but I can look that up in the documentation for openpyxl
– Quantum Nebula
Nov 13 '18 at 16:14
add a comment |
Here's an example using openpyxl:
import openpyxl
filename = 'C:\temp\spreadsheet.xlsx'
wb = openpyxl.load_workbook(filename=filename)
sheet = wb['Sheet1']
new_row = ['column1', 'column2', 'column3']
sheet.append(new_row)
wb.save(filename)
Here's an example using openpyxl:
import openpyxl
filename = 'C:\temp\spreadsheet.xlsx'
wb = openpyxl.load_workbook(filename=filename)
sheet = wb['Sheet1']
new_row = ['column1', 'column2', 'column3']
sheet.append(new_row)
wb.save(filename)
answered Nov 13 '18 at 15:56
adambroadambro
787
787
1
Works flawlessly! Thank you! Now I got to add a border to the appended row, but I can look that up in the documentation for openpyxl
– Quantum Nebula
Nov 13 '18 at 16:14
add a comment |
1
Works flawlessly! Thank you! Now I got to add a border to the appended row, but I can look that up in the documentation for openpyxl
– Quantum Nebula
Nov 13 '18 at 16:14
1
1
Works flawlessly! Thank you! Now I got to add a border to the appended row, but I can look that up in the documentation for openpyxl
– Quantum Nebula
Nov 13 '18 at 16:14
Works flawlessly! Thank you! Now I got to add a border to the appended row, but I can look that up in the documentation for openpyxl
– Quantum Nebula
Nov 13 '18 at 16:14
add a comment |
xlsx is a complex container format, based on xml. You could parse that yourself, but likely you want to check out a module like openpyxl and go from there.
Looking up the documentation for openpyxl, thank you. pointed me into the right direction.
– Quantum Nebula
Nov 13 '18 at 16:19
add a comment |
xlsx is a complex container format, based on xml. You could parse that yourself, but likely you want to check out a module like openpyxl and go from there.
Looking up the documentation for openpyxl, thank you. pointed me into the right direction.
– Quantum Nebula
Nov 13 '18 at 16:19
add a comment |
xlsx is a complex container format, based on xml. You could parse that yourself, but likely you want to check out a module like openpyxl and go from there.
xlsx is a complex container format, based on xml. You could parse that yourself, but likely you want to check out a module like openpyxl and go from there.
answered Nov 13 '18 at 15:45
BerserkerBerserker
552415
552415
Looking up the documentation for openpyxl, thank you. pointed me into the right direction.
– Quantum Nebula
Nov 13 '18 at 16:19
add a comment |
Looking up the documentation for openpyxl, thank you. pointed me into the right direction.
– Quantum Nebula
Nov 13 '18 at 16:19
Looking up the documentation for openpyxl, thank you. pointed me into the right direction.
– Quantum Nebula
Nov 13 '18 at 16:19
Looking up the documentation for openpyxl, thank you. pointed me into the right direction.
– Quantum Nebula
Nov 13 '18 at 16:19
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.
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%2f53284571%2fpython-append-a-row-to-the-end-of-an-xlsx-document%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