You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android中使用Apache POI时HSSFCellStyle的BORDER_MEDIUM未识别问题

Troubleshooting Unrecognized HSSFCellStyle.BORDER_MEDIUM in Android Studio

Hey there, I’ve run into this exact headache with Apache POI before—let’s break down what’s going wrong and fix it!

The Root Cause

Starting with Apache POI 3.17, the old border style constants like HSSFCellStyle.BORDER_MEDIUM were deprecated and moved to a dedicated BorderStyle enum class. If you’re using a newer POI version in your Android project, Android Studio can’t find the constant in HSSFCellStyle anymore because it no longer lives there.

Fix Steps

  1. Update your code to use the BorderStyle enum
    Replace your problematic line with this:

    borderBottom.setBorderBottom(BorderStyle.MEDIUM);
    

    Don’t forget to add the import statement at the top of your file:

    import org.apache.poi.ss.usermodel.BorderStyle;
    
  2. Verify your POI dependency version
    If you’re stuck using the old constant (not recommended, since it’s deprecated), double-check your build.gradle file to ensure you’re using POI 3.16 or earlier. But I’d strongly suggest sticking with the newer enum approach—it’s the standard now and avoids future compatibility issues.

  3. Double-check your core imports
    Make sure you’re pulling in the correct HSSFCellStyle class too:

    import org.apache.poi.hssf.usermodel.HSSFCellStyle;
    

Quick Modified Code Snippet

Here’s how your updated code should look:

public boolean exportToExcel(final Context context, final String fileName){
    if (!isExternalStorageAvailable() || isExternalStorageReadOnly()) {
        Log.e("External Storage", "Storage not available or read only");
        return false;
    }
    resultExcelArrayList = new ArrayList<>();
    success = false;
    String sheetName = "Sheet1";
    wb = new HSSFWorkbook();
    sheet = wb.createSheet(sheetName) ;
    HSSFCellStyle borderBottom = wb.createCellStyle();
    // Use BorderStyle enum instead of old HSSFCellStyle constant
    borderBottom.setBorderBottom(BorderStyle.MEDIUM);
    // 其余代码省略...
}

That should squash the compilation error and get your Excel export back on track!

内容的提问来源于stack exchange,提问作者Cees Graafland

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:44:30