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

How to assign keywords, title in set_properties #30

Open
hulksyed07 opened this issue Jan 31, 2019 · 4 comments
Open

How to assign keywords, title in set_properties #30

hulksyed07 opened this issue Jan 31, 2019 · 4 comments
Assignees

Comments

@hulksyed07
Copy link

hulksyed07 commented Jan 31, 2019

I am trying to set the keyword property in the excel file as 'Confidential' by using the below method

workbook = FastExcel.open('./dummy.xlsx')
workbook.set_properties({ keywords: 'Confidential' })

It gives me error that "Argument is not a valid pointer"

After Going through the gem it looks like that it expects a DocProperties Object

d = Libxlsxwriter::DocProperties.new

d[:keywords] = 'Confidential'

workbook.set_properties(d)

When i try to assign d[:keywords] = 'Confidential' then it gives me error that "Cannot set string field"

Could you please let me know how to assign properties

@Paxa
Copy link
Owner

Paxa commented Feb 5, 2019

I think this is related ffi/ffi#10
Need to make some setter methods... will try to make it easier and documented later.

For now I was able to make it works like this:

require_relative 'fast_excel'

class Libxlsxwriter::DocProperties < FFI::Struct
  def keywords=(val)
    pos = offset_of(:keywords)

    if val.is_a?(String)
      val = FFI::MemoryPointer.from_string(val)
    end

    if val.nil?
      self.pointer.put_pointer(pos, FFI::MemoryPointer::NULL)
    elsif val.is_a?(FFI::MemoryPointer)
      self.pointer.put_pointer(pos, val)
    else
      fail("keywords= requires an FFI::MemoryPointer or nil")
    end

    val
  end
end

workbook = FastExcel.open("example_workbook_properties.xlsx", constant_memory: true)

props = Libxlsxwriter::DocProperties.new
props.keywords = 'Confidential'

workbook.set_properties(props)

# print properties
FastExcel.print_ffi_obj(workbook[:properties])

workbook.close

@Paxa Paxa self-assigned this Feb 5, 2019
@Laykou
Copy link

Laykou commented Jul 14, 2020

@Paxa Is there any way how to make this more simple using hashes?

@Paxa
Copy link
Owner

Paxa commented Jul 22, 2020

@Laykou Not yet, PRs are welcome :)

@Laykou
Copy link

Laykou commented Jul 22, 2020

Yeah, this is a bit low-level to me with the C-like programming, pointers and FFI :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants