Encode decode problem while writing to excell worksheet in django view
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I get below unicodedecodeerror while trying to write to excell worksheet.
Exception Type: UnicodeDecodeError
Exception Value:
'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128) The string that could not be encoded/decoded was: i>����R<
My view lines :
def file_write(input):
handle1=open('/tmp/filelog.txt','a')
handle1.write(str(input))
handle1.close()
workbook = xlsxwriter.Workbook('report.xlsx')
worksheet = workbook.add_worksheet()
teachertitle = "ÖĞR"
file_write(teachertitle)
worksheet.write("A4", teachertitle, titlescell)
workbook.close()
The strange thing is. File_write function is working well and it writes "ÖĞR" to a local text file. But when i try to write "ÖĞR" to excell workseeht it throws error.
I also tried worksheet.write("A4", teachertitle.encode('utf-8'), titlescell) but still problem continue.
I also have # -- coding: utf-8 -- at the beginning of views.py
python django character-encoding django-views django-excel
add a comment |
I get below unicodedecodeerror while trying to write to excell worksheet.
Exception Type: UnicodeDecodeError
Exception Value:
'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128) The string that could not be encoded/decoded was: i>����R<
My view lines :
def file_write(input):
handle1=open('/tmp/filelog.txt','a')
handle1.write(str(input))
handle1.close()
workbook = xlsxwriter.Workbook('report.xlsx')
worksheet = workbook.add_worksheet()
teachertitle = "ÖĞR"
file_write(teachertitle)
worksheet.write("A4", teachertitle, titlescell)
workbook.close()
The strange thing is. File_write function is working well and it writes "ÖĞR" to a local text file. But when i try to write "ÖĞR" to excell workseeht it throws error.
I also tried worksheet.write("A4", teachertitle.encode('utf-8'), titlescell) but still problem continue.
I also have # -- coding: utf-8 -- at the beginning of views.py
python django character-encoding django-views django-excel
1
Are you using python3 or python2? Also, can you please post the full trace to your exception?
– 2ps
Nov 23 '18 at 19:39
The source file encoding should actually be specified with:# -*- coding: utf-8 -*-(note the asterisks).
– Will Keeling
Nov 26 '18 at 10:09
right the original code is with *
– ivbtar
Nov 29 '18 at 14:23
add a comment |
I get below unicodedecodeerror while trying to write to excell worksheet.
Exception Type: UnicodeDecodeError
Exception Value:
'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128) The string that could not be encoded/decoded was: i>����R<
My view lines :
def file_write(input):
handle1=open('/tmp/filelog.txt','a')
handle1.write(str(input))
handle1.close()
workbook = xlsxwriter.Workbook('report.xlsx')
worksheet = workbook.add_worksheet()
teachertitle = "ÖĞR"
file_write(teachertitle)
worksheet.write("A4", teachertitle, titlescell)
workbook.close()
The strange thing is. File_write function is working well and it writes "ÖĞR" to a local text file. But when i try to write "ÖĞR" to excell workseeht it throws error.
I also tried worksheet.write("A4", teachertitle.encode('utf-8'), titlescell) but still problem continue.
I also have # -- coding: utf-8 -- at the beginning of views.py
python django character-encoding django-views django-excel
I get below unicodedecodeerror while trying to write to excell worksheet.
Exception Type: UnicodeDecodeError
Exception Value:
'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128) The string that could not be encoded/decoded was: i>����R<
My view lines :
def file_write(input):
handle1=open('/tmp/filelog.txt','a')
handle1.write(str(input))
handle1.close()
workbook = xlsxwriter.Workbook('report.xlsx')
worksheet = workbook.add_worksheet()
teachertitle = "ÖĞR"
file_write(teachertitle)
worksheet.write("A4", teachertitle, titlescell)
workbook.close()
The strange thing is. File_write function is working well and it writes "ÖĞR" to a local text file. But when i try to write "ÖĞR" to excell workseeht it throws error.
I also tried worksheet.write("A4", teachertitle.encode('utf-8'), titlescell) but still problem continue.
I also have # -- coding: utf-8 -- at the beginning of views.py
python django character-encoding django-views django-excel
python django character-encoding django-views django-excel
asked Nov 23 '18 at 14:35
ivbtarivbtar
140110
140110
1
Are you using python3 or python2? Also, can you please post the full trace to your exception?
– 2ps
Nov 23 '18 at 19:39
The source file encoding should actually be specified with:# -*- coding: utf-8 -*-(note the asterisks).
– Will Keeling
Nov 26 '18 at 10:09
right the original code is with *
– ivbtar
Nov 29 '18 at 14:23
add a comment |
1
Are you using python3 or python2? Also, can you please post the full trace to your exception?
– 2ps
Nov 23 '18 at 19:39
The source file encoding should actually be specified with:# -*- coding: utf-8 -*-(note the asterisks).
– Will Keeling
Nov 26 '18 at 10:09
right the original code is with *
– ivbtar
Nov 29 '18 at 14:23
1
1
Are you using python3 or python2? Also, can you please post the full trace to your exception?
– 2ps
Nov 23 '18 at 19:39
Are you using python3 or python2? Also, can you please post the full trace to your exception?
– 2ps
Nov 23 '18 at 19:39
The source file encoding should actually be specified with:
# -*- coding: utf-8 -*- (note the asterisks).– Will Keeling
Nov 26 '18 at 10:09
The source file encoding should actually be specified with:
# -*- coding: utf-8 -*- (note the asterisks).– Will Keeling
Nov 26 '18 at 10:09
right the original code is with *
– ivbtar
Nov 29 '18 at 14:23
right the original code is with *
– ivbtar
Nov 29 '18 at 14:23
add a comment |
2 Answers
2
active
oldest
votes
The problem is most likely with your file_write function, where you need to set the encoding of the file to be able to handle utf-8. In python3, you can do that using:
def file_write(input):
handle1=open('/tmp/filelog.txt','a', encoding='utf-8')
handle1.write(str(input))
handle1.close()
file_write() is working well. Problem is with excell workbook
– ivbtar
Nov 29 '18 at 14:25
add a comment |
At last,
Solution is :
worksheet.write("A4", teachertitle.decode('utf-8'), titlescell)
Decoding solved it. As i understand excell workbook needs the string to be decoded before writing to excell sheet.
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%2f53448618%2fencode-decode-problem-while-writing-to-excell-worksheet-in-django-view%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
The problem is most likely with your file_write function, where you need to set the encoding of the file to be able to handle utf-8. In python3, you can do that using:
def file_write(input):
handle1=open('/tmp/filelog.txt','a', encoding='utf-8')
handle1.write(str(input))
handle1.close()
file_write() is working well. Problem is with excell workbook
– ivbtar
Nov 29 '18 at 14:25
add a comment |
The problem is most likely with your file_write function, where you need to set the encoding of the file to be able to handle utf-8. In python3, you can do that using:
def file_write(input):
handle1=open('/tmp/filelog.txt','a', encoding='utf-8')
handle1.write(str(input))
handle1.close()
file_write() is working well. Problem is with excell workbook
– ivbtar
Nov 29 '18 at 14:25
add a comment |
The problem is most likely with your file_write function, where you need to set the encoding of the file to be able to handle utf-8. In python3, you can do that using:
def file_write(input):
handle1=open('/tmp/filelog.txt','a', encoding='utf-8')
handle1.write(str(input))
handle1.close()
The problem is most likely with your file_write function, where you need to set the encoding of the file to be able to handle utf-8. In python3, you can do that using:
def file_write(input):
handle1=open('/tmp/filelog.txt','a', encoding='utf-8')
handle1.write(str(input))
handle1.close()
answered Nov 23 '18 at 19:38
2ps2ps
8,16221131
8,16221131
file_write() is working well. Problem is with excell workbook
– ivbtar
Nov 29 '18 at 14:25
add a comment |
file_write() is working well. Problem is with excell workbook
– ivbtar
Nov 29 '18 at 14:25
file_write() is working well. Problem is with excell workbook
– ivbtar
Nov 29 '18 at 14:25
file_write() is working well. Problem is with excell workbook
– ivbtar
Nov 29 '18 at 14:25
add a comment |
At last,
Solution is :
worksheet.write("A4", teachertitle.decode('utf-8'), titlescell)
Decoding solved it. As i understand excell workbook needs the string to be decoded before writing to excell sheet.
add a comment |
At last,
Solution is :
worksheet.write("A4", teachertitle.decode('utf-8'), titlescell)
Decoding solved it. As i understand excell workbook needs the string to be decoded before writing to excell sheet.
add a comment |
At last,
Solution is :
worksheet.write("A4", teachertitle.decode('utf-8'), titlescell)
Decoding solved it. As i understand excell workbook needs the string to be decoded before writing to excell sheet.
At last,
Solution is :
worksheet.write("A4", teachertitle.decode('utf-8'), titlescell)
Decoding solved it. As i understand excell workbook needs the string to be decoded before writing to excell sheet.
answered Nov 29 '18 at 14:27
ivbtarivbtar
140110
140110
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%2f53448618%2fencode-decode-problem-while-writing-to-excell-worksheet-in-django-view%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
1
Are you using python3 or python2? Also, can you please post the full trace to your exception?
– 2ps
Nov 23 '18 at 19:39
The source file encoding should actually be specified with:
# -*- coding: utf-8 -*-(note the asterisks).– Will Keeling
Nov 26 '18 at 10:09
right the original code is with *
– ivbtar
Nov 29 '18 at 14:23