PGS62 / JuliaExcel.jl

Call Julia from Microsoft Excel worksheets and from VBA
MIT License
60 stars 6 forks source link

push! entry #13

Closed rnaldooo closed 1 year ago

rnaldooo commented 1 year ago

im using Clipper when entry push! line return error

using Clipper polygon = IntPoint[] push!(polygon, IntPoint(348,257))

┌ Error: Result of type Vector{IntPoint} could not be encoded for return to Excel. └ @ JuliaExcel C:\Users\reinaldo.julia\packages\JuliaExcel\Y1cgX\src\JuliaExcel.jl:148

PGS62 commented 1 year ago

The problem is that your call to push! returns a Vector{IntPoint} and the relevant function of JuliaExcel (namely encode_for_xl) does not know how to encode that for display in an Excel worksheet. So a solution would be to add a method to encode_for_xl that handles Vector{IntPoint}, by converting the input to Matrix{Int64} and encoding that.

This code achieves that:

import JuliaExcel.encode_for_xl
encode_for_xl(p::Vector{IntPoint}) = encode_for_xl(hcat([p[i].X for i in eachindex(p)],[p[i].Y for i in eachindex(p)]))

image