title: How to disable protected mode for Excel file generated using Apache POI?
body: <p><a href="https://i.stack.imgur.com/YbVXF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YbVXF.png" alt="enter image description here"></a>I'd created excel report(.xls) using Apache POI. Whenever I open it, it's showing a message "PROTECTED VIEW: Office has detected a problem with this file. Editing it may harm your computer". How to disable the protected view and Can I handle this within the code itself?</p>
  
  <p>I'm getting the error message only when I apply the style to the cell.</p>
  
  <pre><code>import java.io.File;
  import java.io.FileOutputStream;
  
  import org.apache.poi.hssf.usermodel.HSSFCell;
  import org.apache.poi.hssf.usermodel.HSSFCellStyle;
  import org.apache.poi.hssf.usermodel.HSSFDataFormat;
  import org.apache.poi.hssf.usermodel.HSSFFont;
  import org.apache.poi.hssf.usermodel.HSSFRow;
  import org.apache.poi.hssf.usermodel.HSSFSheet;
  import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  import org.apache.poi.hssf.util.HSSFColor;
  
  public class Test {
  
  public static void main(String[] args) throws Exception {
  
      HSSFWorkbook wb = new HSSFWorkbook();
      HSSFSheet sheet = null;
  
      HSSFDataFormat dtFormat = wb.createDataFormat();
      HSSFRow row_data = null;
      HSSFCell cell_data = null;
  
      HSSFCellStyle style = null;
      HSSFCellStyle styleSubHeader = null;
      HSSFCellStyle styleLeft = null;
      HSSFCellStyle styleCentre = null;
      HSSFCellStyle styleBRData = null;
      HSSFCellStyle styleRight = null;
      HSSFCellStyle styleRPrec = null;
      HSSFCellStyle styleBold = null;
      HSSFCellStyle styleBRight = null;
      HSSFCellStyle styleBRPrec = null;
      HSSFCellStyle styleBLeftHead = null;
      HSSFCellStyle styleBLeft = null;
      HSSFCellStyle styleBCentre = null;
      HSSFCellStyle styleRRight = null;
      HSSFCellStyle styleSubTitle = null;
      HSSFFont headBold = null;
      HSSFFont titleBold = null;
      HSSFDataFormat dtFmt = null;
  
      HSSFCellStyle styleCenter = wb.createCellStyle();
      HSSFFont fontCenter = wb.createFont();
      HSSFFont font = wb.createFont();
      HSSFFont fontBold = wb.createFont();
      HSSFFont fontsubTitle = wb.createFont();
  
      FileOutputStream out = new FileOutputStream(new File("sample.xls"));
  
      try {
  
          styleSubTitle = wb.createCellStyle();
          sheet = wb.createSheet("Pricing Report");
          row_data = sheet.createRow(sheet.getLastRowNum());
  
          style = wb.createCellStyle();
          style.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);
          style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
          style.setBorderBottom(HSSFColor.TAN.index);
          style.setBorderLeft(HSSFColor.TAN.index);
          style.setBorderRight(HSSFColor.TAN.index);
          style.setBorderTop(HSSFColor.TAN.index);
  
          cell_data = row_data.createCell((short) 0);
          cell_data.setCellValue("Header 1");
          cell_data.setCellStyle(styleSubTitle);
          cell_data.setCellStyle(style);
  
          wb.write(out);
  
          out.close();
  
          System.out.println("Excel Generated");
      } catch (Exception e) {
          e.printStackTrace();
      }
   }
  
  }
  </code></pre>