Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fit to page #112

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/elixlsx/sheet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ defmodule Elixlsx.Sheet do
group_rows: [],
merge_cells: [],
pane_freeze: nil,
show_grid_lines: true
show_grid_lines: true,
show_zeros: false,
fit_to_page: false

@type t :: %Sheet{
name: String.t(),
Expand Down
28 changes: 22 additions & 6 deletions lib/elixlsx/xml_templates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -439,17 +439,18 @@ defmodule Elixlsx.XMLTemplates do
def make_sheet(sheet, wci) do
grouping_info = get_grouping_info(sheet.group_rows)

~S"""
~s"""
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<sheetPr filterMode="false">
<pageSetUpPr fitToPage="false"/>
<pageSetUpPr fitToPage="#{make_sheet_fit_to_page(sheet)}"/>
</sheetPr>
<dimension ref="A1"/>
<sheetViews>
<sheetView workbookViewId="0"
""" <>
make_sheet_show_grid(sheet) <>
make_sheet_show_zeros(sheet) <>
"""
>
""" <>
Expand Down Expand Up @@ -488,6 +489,20 @@ defmodule Elixlsx.XMLTemplates do
show_grid_lines_xml
end

defp make_sheet_show_zeros(sheet) do
case sheet.show_zeros do
true -> ""
false -> ~s[ showZeros="0" ]
end
end

defp make_sheet_fit_to_page(sheet) do
case sheet.fit_to_page do
true -> "1"
_ -> "false"
theevs marked this conversation as resolved.
Show resolved Hide resolved
end
end

defp make_sheetview(sheet) do
# according to spec:
# * when only horizontal split is applied we need to use bottomLeft
Expand Down Expand Up @@ -573,10 +588,11 @@ defmodule Elixlsx.XMLTemplates do
do: 0,
else: FillDB.get_id(wci.filldb, style.fill)

numfmtid =
if is_nil(style.numfmt),
do: 0,
else: NumFmtDB.get_id(wci.numfmtdb, style.numfmt)
numfmtid = case style.numfmt do
nil -> 0
%{format: "# ##0.00"} -> 4
f -> NumFmtDB.get_id wci.numfmtdb, f
end

borderid =
if is_nil(style.border),
Expand Down