xlsxwriter - Looping in value from database and storing in spreadsheet
I have a table that stores column definition as listed below:
Col Name : store_name
Definition : name
Col Name : store_location
Definition : location
Table structure:
store_name,store_location
name,location
I am trying to have these values displayed in an excel spreadsheet using the below loop:
cursor = This queries the table that stores the above info
title_def = [i[0] for i in cursor.description]
row = 5
col = 2
for data in title_def:
worksheet1.write(row, col, data, header_format)
row += 1
The above loop only prints out the label. I am not sure how to modify the title_def above as I believe I am only filtering out the header and that gets displayed in the sheet using xlsxwriter. Could anyone advice how could I display both col_name and definition in the same spreadsheet..
python-3.x xlsxwriter
add a comment |
I have a table that stores column definition as listed below:
Col Name : store_name
Definition : name
Col Name : store_location
Definition : location
Table structure:
store_name,store_location
name,location
I am trying to have these values displayed in an excel spreadsheet using the below loop:
cursor = This queries the table that stores the above info
title_def = [i[0] for i in cursor.description]
row = 5
col = 2
for data in title_def:
worksheet1.write(row, col, data, header_format)
row += 1
The above loop only prints out the label. I am not sure how to modify the title_def above as I believe I am only filtering out the header and that gets displayed in the sheet using xlsxwriter. Could anyone advice how could I display both col_name and definition in the same spreadsheet..
python-3.x xlsxwriter
add a comment |
I have a table that stores column definition as listed below:
Col Name : store_name
Definition : name
Col Name : store_location
Definition : location
Table structure:
store_name,store_location
name,location
I am trying to have these values displayed in an excel spreadsheet using the below loop:
cursor = This queries the table that stores the above info
title_def = [i[0] for i in cursor.description]
row = 5
col = 2
for data in title_def:
worksheet1.write(row, col, data, header_format)
row += 1
The above loop only prints out the label. I am not sure how to modify the title_def above as I believe I am only filtering out the header and that gets displayed in the sheet using xlsxwriter. Could anyone advice how could I display both col_name and definition in the same spreadsheet..
python-3.x xlsxwriter
I have a table that stores column definition as listed below:
Col Name : store_name
Definition : name
Col Name : store_location
Definition : location
Table structure:
store_name,store_location
name,location
I am trying to have these values displayed in an excel spreadsheet using the below loop:
cursor = This queries the table that stores the above info
title_def = [i[0] for i in cursor.description]
row = 5
col = 2
for data in title_def:
worksheet1.write(row, col, data, header_format)
row += 1
The above loop only prints out the label. I am not sure how to modify the title_def above as I believe I am only filtering out the header and that gets displayed in the sheet using xlsxwriter. Could anyone advice how could I display both col_name and definition in the same spreadsheet..
python-3.x xlsxwriter
python-3.x xlsxwriter
asked Nov 24 '18 at 11:40
dark horsedark horse
16010
16010
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
# Loop through cells in Excel and print values
from openpyxl import load_workbook
workbook = load_workbook('C:\your_path\ExcelFile.xlsx')
sheet = workbook.active
row_count = sheet.max_row
for i in range(row_count):
print(sheet.cell(row=i, column=1).value)
# And if you want to do the same with a CSV file
import csv
with open('C:\your_path\CSVFile.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print(row)
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%2f53457743%2fxlsxwriter-looping-in-value-from-database-and-storing-in-spreadsheet%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
# Loop through cells in Excel and print values
from openpyxl import load_workbook
workbook = load_workbook('C:\your_path\ExcelFile.xlsx')
sheet = workbook.active
row_count = sheet.max_row
for i in range(row_count):
print(sheet.cell(row=i, column=1).value)
# And if you want to do the same with a CSV file
import csv
with open('C:\your_path\CSVFile.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print(row)
add a comment |
# Loop through cells in Excel and print values
from openpyxl import load_workbook
workbook = load_workbook('C:\your_path\ExcelFile.xlsx')
sheet = workbook.active
row_count = sheet.max_row
for i in range(row_count):
print(sheet.cell(row=i, column=1).value)
# And if you want to do the same with a CSV file
import csv
with open('C:\your_path\CSVFile.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print(row)
add a comment |
# Loop through cells in Excel and print values
from openpyxl import load_workbook
workbook = load_workbook('C:\your_path\ExcelFile.xlsx')
sheet = workbook.active
row_count = sheet.max_row
for i in range(row_count):
print(sheet.cell(row=i, column=1).value)
# And if you want to do the same with a CSV file
import csv
with open('C:\your_path\CSVFile.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print(row)
# Loop through cells in Excel and print values
from openpyxl import load_workbook
workbook = load_workbook('C:\your_path\ExcelFile.xlsx')
sheet = workbook.active
row_count = sheet.max_row
for i in range(row_count):
print(sheet.cell(row=i, column=1).value)
# And if you want to do the same with a CSV file
import csv
with open('C:\your_path\CSVFile.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print(row)
answered Nov 24 '18 at 17:56
ryguy72ryguy72
4,3861820
4,3861820
add a comment |
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%2f53457743%2fxlsxwriter-looping-in-value-from-database-and-storing-in-spreadsheet%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