473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

prevent cells in excel sheet from being selected through java

I need to prevent the cells in excel from being selected.and it shud be done through java code only.Is there any way to do it?

Here my program generates excel and I need that excel sheet to be protected and its cell from being selected and copied elsewhere.Someone can help??.

The below code helps in making excel read only, and prompts for password when being edited..So pwd protected.But i need the excel sheet to be protected from selection also

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import org.apache.poi.hssf.usermodel.*;
  3.  
  4.  
  5.  
  6. public class PasswordProtectedExcelSheet {
  7.  
  8.  
  9.     public static void main(String arg[]) {
  10.         try{
  11.             FileOutputStream out = new FileOutputStream("c://Sample.xls");
  12.  
  13.  
  14.             HSSFWorkbook hssfworkbook = new HSSFWorkbook();
  15.  
  16.           // hssfworkbook.writeProtectWorkbook("hai","hai"); --> shows same behaviour even if uncommented
  17.  
  18.                HSSFSheet sheet = hssfworkbook.createSheet("welcome");
  19.             String N_NAME = "name";
  20.  
  21.                     HSSFRow row = sheet.createRow(0);
  22.  
  23.                      HSSFCell cell =row.createCell((short)0);
  24.  
  25.                      cell.setCellValue(N_NAME);
  26.  
  27.             //Sets the password for the sheet 
  28.            sheet.protectSheet("xyz");
  29.  
  30.              hssfworkbook.write(out);
  31.             out.close();
  32.         } catch(Exception e){
  33.             e.printStackTrace();
  34.             System.out.println("Exception occured");
  35.         }
  36.     } 
  37.  
  38.   }
Apr 5 '10 #1
5 4832
Is there any way to disable cells in excel sheet being selected??

And can it be done by coding through Java??
Apr 9 '10 #2
jkmyoung
2,057 Expert 2GB
I would write a vbmacro that checks the onSelection event.
Detect if any of the Selection overlaps with forbidden cells.
If so, reset selection to some other cell, eg, A1, and possibly flash a prompt saying that the cell can not be selected.

Add this macro to your sheet. I am unfamiliar with the HSSFWorkbook class structure.
Apr 9 '10 #3
Hi,

Lets forget HSSF..
Other than Vb macro .. is there any way to prevent selection in excel or prevent copying?
be it in , Jsp, java.. using any api , even JXL ..
Am breaking my head...
any help ???
Jun 25 '10 #4
jkmyoung
2,057 Expert 2GB
What do you really want? Prevent people from selecting, or prevent people from copying?

It may be possible with cell/worksheet properties if you protect the sheet before hand.

Excel only uses VB for the most part. You could try some backdoor method through an add-in .dll, but that seems like more work than necessary.
Jun 25 '10 #5
@jkmyoung
yeah...
I ve protected the sheet..that means noone can edit it as such.(password protected using jxl Api)
But I don want anyone to use ctrl+a n copy it in a new exel n edit my contents,.. So it would be better if selection itself is disabled..so I need help there..
Jun 28 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: zxo102 | last post by:
Hi there, I need your help for python <--> excel. I want to paste selected cells (range) to different location on the same sheet in Excel through python. I have tried it for a while but could not...
1
by: Glen Vermeylen | last post by:
Hi, For a project at school we have to automate the assignment of seats in classrooms to students during the exams. The lady who previously did everything manually kept the layouts of the...
0
by: Sol | last post by:
Hello, // Version française : Je travaille sur une appli en vb.net et mon but est de récupérer une sélection faites par un utilisateur sur un fichier excel. Donc en étape : 1 - Ouvrir le...
5
by: mrid via DotNetMonster.com | last post by:
hi. im exporting data from a vb form to excel. i am able to create a new excel file, save and edit it without any trouble, but the formatting is giving me hell! i need to be able to show certain...
4
by: mimasci | last post by:
Hi, I have tried to write a code that allowed me to modify the value of the cells selected in a table, with excel has been easy. How one approaches selected cells? (To modify the value) How...
0
by: naorem ranjan | last post by:
I have one problem regarding format of mixed data columns in excel. I am using ADO.NET to retrieve data from excel sheet. Connection String used is: ...
4
by: ielamrani | last post by:
Hi, I am getting this error when I try to export to an excel sheet. When I click on a button to export the first time it's fine, I rename the exported excel sheet and I try to export it again and I...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
3
by: keirnus | last post by:
hello, been searching for a solution on this but all i get are advices for importing data from excel directly to MS Access DB. my case here is different...the sheet in Excel file is not ready...
8
blazedaces
by: blazedaces | last post by:
So I have a program below which writes an excel file with multiple sheets based on inputs of sheet names, data, cell types, etc. It uses Apache POI, which is currently the only thing I found...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.