Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
6 changes: 0 additions & 6 deletions Artifacts.toml

This file was deleted.

1 change: 0 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ authors = ["Felipe Noronha <felipenoris@gmail.com>"]
repo = "https://github.com/juliadata/XLSX.jl.git"

[deps]
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
Expand Down
4 changes: 0 additions & 4 deletions artifacts_scripts/Project.toml

This file was deleted.

19 changes: 0 additions & 19 deletions artifacts_scripts/build_artifacts.jl

This file was deleted.

2 changes: 0 additions & 2 deletions data/sheet_template.xml

This file was deleted.

Binary file removed relocatable_data/blank.xlsx
Binary file not shown.
3 changes: 1 addition & 2 deletions src/XLSX.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

module XLSX

import Artifacts
import Base.convert
import Base.Threads
import Colors
Expand Down Expand Up @@ -70,7 +69,7 @@ PCT.@setup_workload begin
PCT.@compile_workload begin
# all calls in this block will be precompiled, regardless of whether
# they belong to your package or not (on Julia 1.8 and higher)
f=openxlsx(joinpath(_relocatable_data_path(), "blank.xlsx"), mode="rw")
f=openxlsx(joinpath(@__DIR__, "data", "blank.xlsx"), mode="rw")
f[1]["A1:Z26"] = "hello World"
openxlsx(s, mode="w") do xf
xf[1][1:26, 1:26] = pi
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 3 additions & 7 deletions src/formula.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#----------------------------------------------------------------------------------------------------
# metadata.xml should perhaps better be a package artifact. Put it here in the meantime.
const metadata = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<metadata xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:xda="http://schemas.microsoft.com/office/spreadsheetml/2017/dynamicarray"><metadataTypes count="1"><metadataType name="XLDAPR" minSupportedVersion="120000" copy="1" pasteAll="1" pasteValues="1" merge="1" splitFirst="1" rowColShift="1" clearFormats="1" clearComments="1" assign="1" coerce="1" cellMeta="1"/></metadataTypes><futureMetadata name="XLDAPR" count="1"><bk><extLst><ext uri="{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}"><xda:dynamicArrayProperties fDynamic="1" fCollapsed="0"/></ext></extLst></bk></futureMetadata><cellMetadata count="1"><bk><rc t="1" v="0"/></bk></cellMetadata></metadata>"""
#-----------------------------------------------------------------------------------------------------
include_dependency(joinpath(@__DIR__, "data", "metadata.xml"))
const METADATA_XML_DATA = read(joinpath(@__DIR__, "data", "metadata.xml"))

const RGX_FORMULA_SHEET_CELL = r"!\$?[A-Z]+\$?[0-9]" # to recognise sheetcell references like "otherSheet!A1"

Expand Down Expand Up @@ -616,8 +613,7 @@ function process_dynamic_array_functions(xf::XLSXFile, cellref::CellRef, val::St
ref = cellname(cellref) * ":" * cellname(cellref)
cm = "1"
if !haskey(xf.files, "xl/metadata.xml") # add metadata.xml on first use of a dynamicArray formula
# xf.data["xl/metadata.xml"] = XML.Node(XML.Raw(read(joinpath(_relocatable_data_path(), "metadata.xml"))))
xf.data["xl/metadata.xml"] = parse(metadata, XML.Node)
xf.data["xl/metadata.xml"] = XML.Node(XML.Raw(copy(METADATA_XML_DATA)))
xf.files["xl/metadata.xml"] = true # set file as read
add_override!(xf, "/xl/metadata.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml")
rId = add_relationship!(get_workbook(xf), "metadata.xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sheetMetadata")
Expand Down
14 changes: 5 additions & 9 deletions src/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ opentemplate(source::Union{AbstractString,IO})::XLSXFile = open_or_read_xlsx(sou

@inline open_xlsx_template(source::Union{AbstractString,IO})::XLSXFile = open_or_read_xlsx(source, true, true, true)

function _relocatable_data_path(; path::AbstractString=Artifacts.artifact"XLSX_relocatable_data")
return path
end

"""
newxlsx([sheetname::AbstractString]; update_timestamp::Bool) :: XLSXFile

Expand Down Expand Up @@ -153,15 +149,15 @@ function fix_datestamp!(xf::XLSXFile)
return nothing
end

include_dependency(joinpath(@__DIR__, "data", "blank.xlsx"))
const BLANK_XLSX_DATA = read(joinpath(@__DIR__, "data", "blank.xlsx"))

function open_empty_template(
sheetname::AbstractString="";
path::AbstractString=_relocatable_data_path(),
empty_template_data::Vector{UInt8}=BLANK_XLSX_DATA,
update_timestamp::Bool=true
)::XLSXFile

empty_excel_template = joinpath(path, "blank.xlsx")
!isfile(empty_excel_template) && throw(XLSXError("Couldn't find template file $empty_excel_template."))
xf = open_xlsx_template(empty_excel_template)
xf = open_xlsx_template(IOBuffer(empty_template_data))
xf[1].cache.is_full = true

if sheetname != ""
Expand Down
10 changes: 6 additions & 4 deletions src/write.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,9 @@ function renamesheet!(ws::Worksheet, name::AbstractString)
nothing
end

include_dependency(joinpath(@__DIR__, "data", "sheet_template.xml"))
const SHEET_TEMPLATE_XML_DATA = read(joinpath(@__DIR__, "data", "sheet_template.xml"))

"""
addsheet!(wb::Workbook, [name::AbstractString=""]) --> ::Worksheet
addsheet!(xf::XLSXFile, [name::AbstractString=""]) --> ::Worksheet
Expand All @@ -1121,10 +1124,9 @@ See also [renamesheet!](@ref), [copysheet!](@ref), [deletesheet!](@ref)

"""
addsheet!(xl::XLSXFile, name::AbstractString="")::Worksheet = addsheet!(get_workbook(xl), name)::Worksheet
function addsheet!(wb::Workbook, name::AbstractString=""; relocatable_data_path::String=_relocatable_data_path())::Worksheet
file_sheet_template = joinpath(relocatable_data_path, "sheet_template.xml")
!isfile(file_sheet_template) && throw(XLSXError("Couldn't find template file $file_sheet_template."))
bytes = read(file_sheet_template)
function addsheet!(wb::Workbook, name::AbstractString=""; sheet_template_data::Vector{UInt8}=SHEET_TEMPLATE_XML_DATA)::Worksheet
# Copy so the global SHEET_TEMPLATE_DATA isn't accidentally changed
bytes = copy(sheet_template_data)
f, _ = skipNode(XML.Raw(bytes), "sheetData")
xdoc = XML.Node(XML.Raw(f))

Expand Down
10 changes: 7 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ data_directory = joinpath(dirname(pathof(XLSX)), "..", "data")

@assert isdir(data_directory)

src_data_directory = joinpath(dirname(pathof(XLSX)), "data")

@assert isdir(src_data_directory)

@testset "read test files" begin
ef_blank_ptbr_1904 = XLSX.readxlsx(joinpath(data_directory, "blank_ptbr_1904.xlsx"))
ef_Book1 = XLSX.readxlsx(joinpath(data_directory, "Book1.xlsx"))
Expand Down Expand Up @@ -74,9 +78,9 @@ data_directory = joinpath(dirname(pathof(XLSX)), "..", "data")
end

@testset "Read invalid XLSX error" begin
@test_throws XLSX.XLSXError XLSX.readxlsx(joinpath(data_directory, "sheet_template.xml"))
@test_throws XLSX.XLSXError XLSX.readxlsx(joinpath(src_data_directory, "sheet_template.xml"))
try
XLSX.readxlsx(joinpath(data_directory, "sheet_template.xml"))
XLSX.readxlsx(joinpath(src_data_directory, "sheet_template.xml"))
@test false # didn't throw exception
catch e
@test occursin("is not a valid XLSX file", "$e")
Expand Down Expand Up @@ -6545,7 +6549,7 @@ end

@testset "show xlsx" begin
@testset "single sheet" begin
xf = XLSX.readxlsx(joinpath(data_directory, "blank.xlsx"))
xf = XLSX.readxlsx(joinpath(src_data_directory, "blank.xlsx"))
show(IOBuffer(), xf)
end

Expand Down
Loading