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

Free Support Forum - aspose.com

Make Excel file Read Only

Hi All,

I need to create the excel file read only so that the user should not modify it.
I tried with ProtectionType.MODIFY_FILE but it is not making the file READONLY.

Can any one guide me please .

Regards,
Amol.


Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Please try the workbook.protectFile(ProtectionType.MODIFY_FILE,"aspose") to protect your file. Please see the following sample code in this regard,

Sample Code:

Workbook workbook = new Workbook();

//Open the protected workbook.

workbook.open("c:\\book1.xls");

workbook.protectFile(ProtectionType.MODIFY_FILE,"aspose");

workbook.save("c:\\book1.xls");

For further details you can see the following thread,

Thank You & Best Regards,


Thanks for quick reply.

But it is not working…

I am creating a excel file and putting it to outputstream. Here I want to make it Read Only
e.g:
response.setContentType(“application/vnd.ms-excel”);
response.setHeader(“Content-Disposition”, “inline; filename=”+filename);
OutputStream out = response.getOutputStream();
workbook.save(out);


Regards,
Amol


Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Well, I have tested your scenario and it worked fine with me. Following is my sample code,

Sample Code:

OutputStream out = response.getOutputStream();
response.setContentType("application/vnd.ms-excel");
response.addHeader("content-disposition", "inline; filename=" + "AddingHyperlinks.xls");

Workbook workbook = new Workbook();

Worksheets worksheets = workbook.getWorksheets();
Worksheet worksheet = worksheets.getSheet(0);

Cells cells = worksheet.getCells();
Cell cell;
/* Adding link to a URL */
//Put a value into a cell
cell = cells.getCell("A1");
cell.setValue("Visit Aspose");
Style style = cell.getStyle();
Font font = new Font();
font.setColor(Color.BLUE);
font.setUnderline(Font.UNDERLINE_SINGLE);
style.setFont(font);
cell.setStyle(style);

//Add a hyperlink to a URL at "A1" cell
worksheet.getHyperlinks().add("A1", "B1", "http://www.aspose.com", "Hello Aspose", "1");

/*Adding a link to an external file*/
//Put a value into a cell
cell = cells.getCell("A5");
cell.setValue("SmartMarkerDesigner.xls");

String FILE_PATH_PART = "/WEB-INF/Designer/SmartMarkerDesigner.xls";
ServletContext sc = getServletContext();
String template_file_path = sc.getRealPath(FILE_PATH_PART);

//Add a hyperlink to a URL at "B2" cell
worksheet.getHyperlinks().add(4, 0, 4, 1, template_file_path, "Excel File", "1");
workbook.protectFile(ProtectionType.MODIFY_FILE,"aspose");
//Saving the Excel file
workbook.save(out);

Please share your code and also which version of Aspose.Cells for Java are you using? You can try

the attached latest version if you are using some old version.

Thank You & Best Regards,

Hi,
very glad to see your quick reply.

I have almost the same code as you have given.
There is no much change except the data.
But it is not working…
So I tried the jar attachment given by you.
But still it did not worked.

I am using free version. Does it work with Licensed version ?

Thanks,
Amol


Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.

Well, it should work in the free / evaluation version as well. Please share you complete code here so we can check if it works fine with us or not.

Thank You & Best Regards,