Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
aa.gusti
/
opensipkd-tools
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 0b2a3f82
authored
Mar 01, 2026
by
aa.gustiana@gmail.com
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
perbaikan excel writer
1 parent
ef2b6867
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
5 deletions
opensipkd/tools/report.py
opensipkd/tools/report.py
View file @
0b2a3f8
...
...
@@ -254,21 +254,44 @@ def csv_response(request, value, filename=None):
return
response
def
xls_response
(
request
,
value
,
filename
=
None
):
def
xls_response
(
request
,
value
,
filename
=
None
,
header_format
=
None
):
if
not
filename
:
filename
=
get_random_string
(
20
)
+
".xls"
response
=
request
.
response
response
.
content_type
=
'application/xls'
response
.
content_disposition
=
'filename='
+
filename
from
pandas
import
DataFrame
df
=
DataFrame
(
value
.
get
(
'rows'
,
[]),
columns
=
value
.
get
(
'header'
,
[]))
df
.
to_excel
(
filename
,
index
=
False
)
import
pandas
as
pd
df
=
pd
.
DataFrame
(
value
.
get
(
'rows'
,
[]),
columns
=
value
.
get
(
'header'
,
[]))
writer
=
pd
.
ExcelWriter
(
filename
,
engine
=
'xlsxwriter'
)
# Get the xlsxwriter workbook and worksheet objects.
workbook
=
writer
.
book
# Use this if creating multiple sheets, but here we just need one for simplicity
worksheet
=
writer
.
sheets
# Add a header format. You can customize properties like fg_color (fill color),
# bold, text_wrap, border, etc.
if
header_format
is
None
:
header_format
=
{
'bold'
:
True
,
'text_wrap'
:
True
,
'valign'
:
'top'
,
'fg_color'
:
'#D7E4BC'
,
# Example color (light green)
'border'
:
1
}
hformat
=
workbook
.
add_format
(
header_format
)
df
.
to_excel
(
writer
,
sheet_name
=
'Sheet1'
,
startrow
=
1
,
header
=
False
,
index
=
False
)
# Write the column headers with the defined format.
for
col_num
,
value
in
enumerate
(
df
.
columns
.
values
):
writer
.
sheets
[
'Sheet1'
]
.
write
(
0
,
col_num
,
value
,
hformat
)
writer
.
close
()
# writer.save()
with
open
(
filename
,
'rb'
)
as
f
:
response
.
write
(
f
.
read
())
return
response
def
terbilang
(
bil
):
angka
=
[
""
,
"Satu"
,
"Dua"
,
"Tiga"
,
"Empat"
,
"Lima"
,
"Enam"
,
"Tujuh"
,
"Delapan"
,
"Sembilan"
,
"Sepuluh"
,
"Sebelas"
]
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment