Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6827127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:13:47+00:00 2026-05-26T22:13:47+00:00

I want to create excel files in Groovy, then have them plotted. This code

  • 0

I want to create excel files in Groovy, then have them plotted. This code was taken from an example using Microsoft’s Shell Scripting language:

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Set objWorksheet = objWorkbook.Worksheets(1)

objWorksheet.Cells(1,1) = "Operating System"
objWorksheet.Cells(2,1) = "Windows Server 2003"
objWorksheet.Cells(3,1) = "Windows XP"
objWorksheet.Cells(5,1) = "Windows NT 4.0"
objWorksheet.Cells(6,1) = "Other"

objWorksheet.Cells(1,2) = "Number of Computers"
objWorksheet.Cells(2,2) = 145
objWorksheet.Cells(3,2) = 987
objWorksheet.Cells(4,2) = 611
objWorksheet.Cells(5,2) = 41
objWorksheet.Cells(6,2) = 56

Set objRange = objWorksheet.UsedRange
objRange.Select

Set colCharts = objExcel.Charts
colCharts.Add()

Set objChart = colCharts(1)
objChart.Activate

objChart.HasLegend = FALSE
objChart.ChartTitle.Text = "Operating System Use"

How would I modify this to work in Groovy?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:13:48+00:00Added an answer on May 26, 2026 at 10:13 pm

    You need groovy to work with COM. Towards the bottom of this page is an example of automating Excel.

    EDITS

    Here’s your example translated into Groovy (I ran this under Groovy 1.8.2):

    import org.codehaus.groovy.scriptom.*
    import org.codehaus.groovy.scriptom.tlb.office.excel.XlChartType
    import org.codehaus.groovy.scriptom.tlb.office.excel.XlRowCol
    import org.codehaus.groovy.scriptom.tlb.office.excel.XlChartLocation
    
    // create a xls instance
    def xls = new ActiveXObject("Excel.Application")
    
    xls.Visible = true
    
    Thread.sleep(1000)
    
    // get the workbooks object
    def workbooks = xls.Workbooks
    // add a new workbook
    def workbook  = workbooks.Add()
    
    // select the active sheet
    def sheet = workbook.ActiveSheet
    
    cell = sheet.Range("A1")
    cell.Value = "Operating System"
    cell = sheet.Range("A2")
    cell.Value = "Windows Server 2003"
    cell = sheet.Range("A3")
    cell.Value = "Windows XP"
    cell = sheet.Range("A4")
    cell.Value = "Windows NT 4.0"
    cell = sheet.Range("A5")
    cell.Value = "Other"
    
    cell = sheet.Range("B1")
    cell.Value = "Number of Computers"
    cell = sheet.Range("B2")
    cell.Value = 145
    cell = sheet.Range("B3")
    cell.Value = 987
    cell = sheet.Range("B4")
    cell.Value = 611
    cell = sheet.Range("B5")
    cell.Value = 41
    
    def chart = workbook.Charts.Add(Scriptom.MISSING, sheet)  // create chart object
    chart.ChartType = XlChartType.xl3DArea // set type to pie
    chart.SetSourceData(sheet.Range("A1:B5"), XlRowCol.xlColumns) // set source data
    chart.Location(XlChartLocation.xlLocationAsNewSheet) // add chart as new sheet
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create XML file from my Excel file through .NET (c#). My
C# or VB.NET suggestion are welcome. I have the following code to create Excel
I have multiple excel files which I open as datatable I want to merge
I want to create a excel 2010 file from C# so what will be
I'm using osx and want to create and edit json files. Is there a
I need to create excel file through code in iPhone i have two array
I want create a excel with Apache POI in java and I must insert
I want to know if PHPExcel can: Create Excel spreadsheets with embeded image. The
i want create image animation , i have 50 images with png format now
I want to create a Java application bundle for Mac without using Mac. According

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.