We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to get WorkBook title in Java cells

Hi,
Do we support file title on the cells for java?
I read the doc and tried coding, and only found workbook.getTheme(), not the getTitle(), like your other family do have this function.
On the MicroSoft excel do have file property summary with title,…

Thanks,

@yhBlue

Thanks for using Aspose APIs.

Please use the Workbook.CreateBuiltinStyle() method for your needs. Here is a Java as well as C# code. Please check the output Excel file generated by the code for your reference. All links are given below.

After downloading, remove its extension or rename it as output.xlsx
output.xlsx.remove.zip (6.2 KB)

sc.png (14.6 KB)

Java

//Create workbook
Workbook wb = new Workbook();

//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);

//Access C4 cell and add a message inside it
Cell cell = ws.getCells().get(“C4”);
cell.putValue(“This is a Title Built-in Style”);

//Create a Title Built-in Style and apply to the cell
Style st = wb.createBuiltinStyle(BuiltinStyleType.TITLE);
cell.setStyle(st);

//Save the workbook
wb.save(dirPath + “output.xlsx”);

C#

//Create workbook
Workbook wb = new Workbook();

//Access first worksheet
Worksheet ws = wb.Worksheets[0];

//Access C4 cell and add a message inside it
Cell cell = ws.Cells[“C4”];
cell.PutValue(“This is a Title Built-in Style”);

//Create a Title Built-in Style and apply to the cell
Style st = wb.CreateBuiltinStyle(BuiltinStyleType.Title);
cell.SetStyle(st);

//Save the workbook
wb.Save(“output.xlsx”);

Hi Shakeel,

Thanks for the reply,

But I can’t open your two files with link, I got erroras the following:
Sorry, this file is private. Only visible to post creator and staff members.

By the way my question is to get existing excel file title, because convert excel file to image maybe need the info. Maybe need to create title for existing excel file without title.

Regard,

@yhBlue,

We are sorry that you could not download the attachments. I have intimated the respective team and they will be fixing the issue soon.

In the meantime, you may download the attachment from dropbox here:


Do you need to retrieve or manipulate Document properties e.g Title, Subject, Author,etc.? Please elaborate your requirements more and give us a sample Excel document and attach some screenshots to explain your needs, we will check it soon.

Thank you.

Hi Amjad,

Thanks for the help,

I do get your zip file and unzip it, all are xml files,…I don’t know how to apply them,…

My key question is that the sample code on the above is to set title on the cell, is it?

We want is to open a existing excel file, if there is title for the workbook then we want it or there is null just tell us null.

From the above sample code I understand is that create title for the cell, is it?

Regards,

@yhBlue,

Yes, as per the screenshot, the sample code (shared previously) actually specifies a built-in Title (style) of MS Excel on a cell’s text.

Could you provide us a sample Excel file here to show your requirements, we will check and help you on how to do it via Aspose.Cells APIs. You can create the sample Excel file (with your desired title) manually in MS Excel and save it.

Thank you.

Hi Amjad,

Thanks for the reply,

I attached two excel files:(because your web don’t allow to upload .xls file, I put the URL here)

  1. with title : http://spreadsheetpage.com/downloads/xl/yearly-calendar-with-holidays.xls

  2. without title:inside the download from github:
    Aspose.Cells-for-Java-master/Examples/bin/resources/TechnicalArticles/book2.xlsx

In the above two case we like to get the title or null.

Regards.

@yhBlue,

Thanks for sharing the template file.

I have checked the “yearly-calendar-with-holidays.xls” file and found it has a main year header and sub-titles for months, etc… Which title you are talking about, e.g
C3–> theyear
or
C5, K5, S5, etc. —> January, February, March, etc.
or something else?

please elaborate and provide more details about your requirements, so we could understnad your better.
.
Well, to evaluate if the header cell has some value or not, you may get the relevant cell (e.g C3) in the worksheet and then evaluate if it is null or not. See the sample code below:
e.g
Sample code:

//Open the Excel file.
Workbook workbook = new Workbook("yearly-calendar-with-holidays.xls");
//Since your workbook has formulas and some values are based on calculated results, 
//so it is better to calculate all the formulas first.
workbook.calculateFormula();
//Get the C3
Cell cell = workbook.getWorksheets().get("Sheet1").getCells().checkCell(2,2);
//Or
//Cell cell = workbook.getWorksheets().get("Sheet1").getCells().get("C3");

 if (cell == null)
        {
         
              //Your code goes here.
          
        };

        //Get the value. 
        System.out.println(cell.getStringValue());
	//Your code goes here.
        //.......... 

Hope, this helps a bit.

Thank you.

Hi Amjad,

Thanks for the help,

For the yearly-calendar-holidays.xls file I am look for tile: "Array Formula Calendar"Screen Shot 2017-06-27 at 11.53.27 AM.png (68.1 KB)

The Best

@yhBlue,

Thanks for the screenshot.

Now we understand your requirements. Actually you need to retrieve certain document properties. We recommend you see the document for your reference:
https://docs.aspose.com/display/cellsjava/Managing+Document+Properties

I have also written the sample code to retrieve “Title” property and some other properties for your reference:
e.g
Sample code:

Workbook workbook = new Workbook("yearly-calendar-with-holidays.xls");
DocumentPropertyCollection customProperties = workbook.getWorksheets().getBuiltInDocumentProperties();

DocumentProperty customProperty1= customProperties.get("Title");
String prop1 = (String)customProperty1.getValue(); 
System.out.println(prop1);

DocumentProperty customProperty2= customProperties.get("Author");
String prop2 = (String)customProperty2.getValue(); 
System.out.println(prop2);

DocumentProperty customProperty3= customProperties.get("Comments");
String prop3 = (String)customProperty3.getValue(); 
System.out.println(prop3);

Console output:
Array Formula Calendar
John Walkenbach
… null …

Let us know if we can be of any further help.

Thank you.