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

  • SEARCH
  • Home
  • 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 5964409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:25:37+00:00 2026-05-22T19:25:37+00:00

I wrote a program that creates a set of data that is outputted to

  • 0

I wrote a program that creates a set of data that is outputted to an excel spreadsheet. I was originally using the jexcel library to write the data to the file, but I’d like to update the program so that it can check and see whether is should create a “.xls” or “.xlsx” file, then write to the appropriate document type. Apache POI seems to be the best option in terms of writing to a “.xlsx” file, but any ideas about determining the correct file type?

I could just have the user choose when naming the file, but that seems like extra work for the user and I’m assuming that there are users who don’t know what file type they’d want.

Any ideas?

Also, I’m assuming the OS is windows and the user has some version of excel, in other cases I’ll just choose a default file type.

  • 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-22T19:25:38+00:00Added an answer on May 22, 2026 at 7:25 pm

    One way is to call the Windows ASSOC and FTYPE commands, capture the output and parse it to determine the Office version installed.

    C:\Users\me>assoc .xls
    .xls=Excel.Sheet.8
    
    C:\Users\me>ftype Excel.sheet.8
    Excel.sheet.8="C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE" /e
    

    Here a quick example :

    import java.io.*;
    public class ShowOfficeInstalled {
        public static void main(String argv[]) {
          try {
            Process p = Runtime.getRuntime().exec
              (new String [] { "cmd.exe", "/c", "assoc", ".xls"});
            BufferedReader input =
              new BufferedReader
                (new InputStreamReader(p.getInputStream()));
            String extensionType = input.readLine();
            input.close();
            // extract type
            if (extensionType == null) {
              System.out.println("no office installed ?");
              System.exit(1);
            }
            String fileType[] = extensionType.split("=");
    
            p = Runtime.getRuntime().exec
              (new String [] { "cmd.exe", "/c", "ftype", fileType[1]});
            input =
              new BufferedReader
                (new InputStreamReader(p.getInputStream()));
            String fileAssociation = input.readLine();
            // extract path
            String officePath = fileAssociation.split("=")[1];
            System.out.println(officePath);
          }
          catch (Exception err) {
            err.printStackTrace();
          }
        }
      }
    

    You may want to add more error checking and the parsing to extract the Office version from the returned path is left as an exercise 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a small program, that creates files at an interval of 1 minute.
From C Primer Plus 5th Ed: Write a program that creates two eight-element arrays
I am writing a Macro in excel VBA that creates a data validation list
I have wrote a server program that can handle multiple client by using fork().
I wrote a program that forks some processes with fork(). I want to kill
I wrote a program that accepts and outputs Hebrew (i.e. right-to-left) text. In lieu
I wrote a program that worked as a server. Knowing that accept was blocking
I recently wrote a program that used a simple producer/consumer pattern. It initially had
A while ago, I wrote a program that outputs any localhost or network database
I wrote a little program that solves 49151 sudoku's within an hour for an

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.