Highlighting cells in POI Excel can be done by repairing records with the specified format located in the /xl/style.xml part(styles)

When I open the processed file (.xlsx) in Ms-Excel-2007 after executing the code for highlighting cells, two pop-ups are appearing. Below is the code and images:


HSSFWorkbook xlsWB = new HSSFWorkbook(file1InputStream);

XSSFWorkbook xlsxWB = new XSSFWorkbook(file2InputStream);

CellStyle xlsxStyle = getCellStyle(xlsxWB);

int numbeoOfSheetsFile1 = xlsWB.getNumberOfSheets();
int numbeoOfSheetsFile2 = xlsxWB.getNumberOfSheets();

for (int sheetIndex = 0; sheetIndex < numbeoOfSheetsFile1 && sheetIndex < numbeoOfSheetsFile2; sheetIndex++) {

   HSSFSheet sheetFile1 = xlsWB.getSheetAt(sheetIndex);
   XSSFSheet sheetFile2 = xlsxWB.getSheetAt(sheetIndex);

   // Remaining code continues here...

Answer №1

This issue persists in my current setup. I am utilizing version 2.4.1 of the NuGet NPOI package, which includes a bugfix for the FontHeight property but has also introduced this new problem.

The main issue is that the font size returned by xssfWorkbook.createFont() is excessively small. To address this, you need to explicitly set it as follows:

    IFont font = excel.CreateFont();
    font.FontHeightInPoints = 11;

I have encountered similar errors when working with files that were previously repaired. It is important to ensure that you write to a new file each time you modify your code to avoid any lingering corruptions from affecting your work.

Here is a complete example showcasing how to handle header cell styles:

    /// <summary>
    /// Return style for header cells.
    /// </summary>
    /// <returns></returns>
    private static ICellStyle GetHeaderStyle(this XSSFWorkbook excel)
    {
        IFont font = excel.CreateFont();
        font.IsBold = true;
        //Manually setting font size to address initial tiny font
        font.FontHeightInPoints = 11;

        ICellStyle style = excel.CreateCellStyle();
        style.FillForegroundColor = IndexedColors.Grey25Percent.Index;
        style.FillPattern = FillPattern.SolidForeground;
        style.FillBackgroundColor = IndexedColors.Grey25Percent.Index;          

        style.BorderBottom = style.BorderLeft = style.BorderRight = style.BorderTop = BorderStyle.Thin;
        style.BottomBorderColor = style.LeftBorderColor = style.RightBorderColor = style.TopBorderColor = IndexedColors.Black.Index;

        style.SetFont(font);
        return style;
    }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The React website using a Gatsby template is encountering an issue where blog posts are not appearing in sequential order on the page, resulting in unexpected gaps between

I'm currently working with a Gatsby template from html5up and encountering an issue where the block posts are not stacking properly. It seems that due to varying text lengths in each post, there are gaps depending on the screen size. I've made al ...

Can we confirm that manually entered text exists in a text field in order to test the functionality of an 'Undo' button?

In my application, there is a table displayed with a form located below it. Users are able to input information into the form fields, and by clicking the 'Undo' button, all entered data will be reverted back to its original state before any edits ...

Jekyll latex not displaying on the remote server, despite being visible on the local server

Why isn't the Jekyll latex showing up on the remote site but appears locally? Currently using the Jekyll minima theme. ...

Instructions for displaying emotes and UTF-8 characters in a Flutter/Java app

In my efforts to display text in Flutter, I am facing the challenge of ensuring that the text is encoded in UTF-8 and can also show emojis. Unfortunately, I have not been successful in achieving both simultaneously. When attempting to decode an input with ...

An error occurred while attempting to parse a JSON string using the Jackson library

Below is the JSON data I am attempting to parse utilizing the Jackson Java library. It represents a Vector of BackgroundShapes, where BackgroundShape subclasses include: BGRectangle BGCircle Within this JSON snippet, there are 2 BGRectangles, but it ma ...

Is it wise to use the<sup>attribute for mandatory form fields?

Would it be wise to utilize the <sup> tag instead of using margin-top: -xnumberofpx for indicating required fields in a form? <label for="address1" required>Address line 1<sup><img src="/src/images/requiredAsterix.png" width="10" heig ...

Update the background's color by cycling through a set of colors stored in

I have a container on my webpage with a light blue background, and I want the background color to darken progressively with each click. Currently, I am manually setting an array of colors for this purpose, but I am struggling to make the background color c ...

When executing the testng.xml file, an error indicating "Invoked Methods" has

I encountered a Null pointer exception when running selenium with the testng.xml file. Surprisingly, everything works fine when I directly run the Login class. However, I really want to utilize groups in my .xml file. Here is a snippet from my testng.xml: ...

Determining complete webpage loading with phantomjsdriver in java

In this scenario, I am utilizing phantomjsdriver to extract the content of web pages. While I can successfully retrieve the full content of static pages, I encounter difficulties with dynamic pages that involve ajax calls. The code snippet below allows me ...

Display an image in a DIV by loading it from a URL provided in a TEXT BOX

I am having trouble loading an image into a div tag from a URL that is obtained from a text box. Here is my current code snippet, but I can't figure out what else needs to be done: <html lang="en"> <head> </head> <bod ...

Utilizing border-image property to showcase four dots in each corner of my div container

I'm having trouble applying a gradient color to my border using the border-image property. When I use border-image: linear-gradient(-180deg, #2D6BD0 0%, #83B8FF 100%);, I'm only seeing a single dot in each corner of my DIV. Does anyone know why t ...

Feeling utterly bewildered by a project involving 2D arrays and generating random numbers

To fill a 2D array with random numbers ranging from 1 to 5, the numbers must be generated using the system time in nanoseconds. The process is a bit intricate. Assuming the array has 5 rows and 5 columns, it would be represented as: ... ... ... ... ... . ...

Challenges arise when attempting to convert oracle.sql.TIMESTAMPTZ to a string format

I am trying to retrieve data from an Oracle database, convert it to JSON format, and use it in another place. However, I am facing an issue with converting the TIMESTAMPTZ data type. In Oracle, the timestamp with timezone is provided as a string in the fol ...

Enhancing form fields with informative tooltips

I found this helpful tutorial on how to create tooltips for form fields using jQuery: It appears that the jQuery function in the article uses ".tooltip" as the default CSS class name for styling the tooltips. Is there a way to customize or change the defa ...

Technique for ensuring consistent kerning across various browsers

Seeking advice on implementing kerning technique for a logotext in the <header>, ensuring cross-browser compatibility. Using this helpful tool created by Mr. Andrew (special thanks), I found a solution. Prior to the modification, the <header> ...

When implementing $().html, certain impacts of mdui may fade away

I've been exploring the functionalities provided by mdui.org, specifically the panel feature. Initially, I had successfully integrated the codes into the HTML body with no issues. View the code here See the screen capture here This allowed me to to ...

The React application encountered a Network Error when making an Axios get request to the Spring Boot application

I'm facing an issue with my SpringBoot application that has a @Controller endpoint set up to accept a getRequest to localhost:8080/all and return JSON data. When I access this domain directly in the browser, I can see the JSON response without any pro ...

What exactly is the testing methodology of Selenium 2.0 software?

I am curious to hear your thoughts on this. Is Selenium considered a Black Box Testing tool, or does it fall under the category of Unit Testing or Integration Testing? ...

Make changes to external CSS using HTML and JavaScript

Is it possible to dynamically change the value of a background in an external CSS file using JavaScript? Currently, all my pages are connected to a CSS file that controls the background for each page. I am attempting to modify the background by clicking a ...

Issue with list-style-image not displaying properly in Gmail on Chrome browser

Having trouble incorporating images into bullet lists in my email templates, specifically with Chrome. I prefer using list-style-image over background-image on the li tag. Is there a solution for this issue? ul { list-style-image: url('../images/Bull ...