Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mata function error - removing gridlines from excel

    I have been writing put excel code into Stata, and have then applied some mata code at the end of my script to make the column widths a nice size etc. However what I would like to do is remove the gridlines from my excel file from which I have been writing my data into....

    My code currently is:

    mata
    b = xl()
    b.load_book("G:\Insight Inteligence and Analytics\From 2022 onwards\1 IandA Framework\B2 Dashboards\EDI Data\EDI Factsheets 2023\STATA\Powerquery\AS\edifactsheet_webfile_TEST _20230419.xlsx")
    b.set_sheet("Age")
    b.set_column_width(1,1,17)
    b.set_column_width(5,5,10)
    b.set_gridlines("off")
    b.close_book()
    end



    without the line b.set_gridlines("off") the code runs without error...however with that line included I appear to be getting the below error message:

    set_gridlines() not declared in class xl
    r(3000);


    I cannot seem to figure out what is causing this error or how to correct it for it to work and wondered if someone please could help me. Thank you for reading.

  • #2
    It seems you aren't using version 18
    try:
    Code:
    mata
    b = xl()
    b.load_book("G:\Insight Inteligence and Analytics\From 2022 onwards\1 IandA Framework\B2 Dashboards\EDI Data\EDI Factsheets 2023\STATA\Powerquery\AS\edifactsheet_webfile_TEST _20230419.xlsx")
    b.set_sheet("Age")
    b.set_column_width(1,1,17)
    b.set_column_width(5,5,10)
    b.mata
    b = xl()
    b.load_book("G:\Insight Inteligence and Analytics\From 2022 onwards\1 IandA Framework\B2 Dashboards\EDI Data\EDI Factsheets 2023\STATA\Powerquery\AS\edifactsheet_webfile_TEST _20230419.xlsx")
    b.set_sheet("Age")
    b.set_column_width(1,1,17)
    b.set_column_width(5,5,10)
    b.set_sheet_gridlines("Age", "off")
    b.close_book()
    end("off")
    b.close_book()
    end
    Kind regards

    nhb

    Comment


    • #3
      Dear Niels, Thank you SO SO MUCH for your assistance with this. While the above code did not immediately work without error, using your code I re-wrote to the below which was effective! You are awesome! Thank you!

      mata
      b = xl()
      b.load_book("G:\Insight Inteligence and Analytics\From 2022 onwards\1 IandA Framework\B2 Dashboards\EDI Data\EDI Factsheets 2023\STATA\Powerquery\AS\edifactsheet_webfile_TEST _20230419.xlsx")
      b.set_sheet("Age")
      b.set_sheet_gridlines("Age", "off")
      b.set_column_width(1,1,17)
      b.set_column_width(5,5,10)
      b.close_book()
      end

      Comment

      Working...
      X