整张纸张受到保护时如何取消单张exel纸张的保护 [英] How to unprotect single column of exel sheet when whole sheet is protected

查看:91
本文介绍了整张纸张受到保护时如何取消单张exel纸张的保护的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我编写了一个程序,将各个数据从xml文件写入excel表,在写完数据后,程序将保护整个excel表用密码。所以现在我应该保护整个excel表,但除了一列。我需要有关如何做到这一点的帮助。



根据下面的代码,我正在从.Xml文件中读取名称,城市,区域和时间等数据在上面的代码中声明的路径为Excelpath并且在excel表中记录相应的数据。



我已经用密码abcd保护excel表但我需要unprotect 5th Column表示数据被写入名称,城市,时间,区域等前四列。因此,对于第5列,我需要让用户可编辑。



我尝试过:



Hi,

I have written a program which writes respective data from xml files to excel sheet, after writing the data, the program will protect the entire excel sheet with a password. So now i should protect entire excel sheet, but except one column. I need help of how to do that.

As per the below code i am reading data like Name, City, Area and Time from .Xml files which are at a path declared in the above code as "Excelpath" and wrtiting the respective data in excel sheet.

I have Protected the excel sheet with password "abcd" but i need to unprotect 5th Column that means the data is written on to first four columns like name, city, time, area. So for 5th column i need to have user editable.

What I have tried:

Excel.Application oXL = null;
Excel.Workbook oWB = null;
Excel.Worksheet excelWorksheet = null;
Excel.Sheets excelSheets = null;
Excel.Worksheet oSheet = null;

//XML Library Declarations
XmlDocument doc = new XmlDocument();
log.Info(excelPATH);
//Declarations
bool isItFirstRow = true;
CurrentRow = 8;
///Process
try
{
	if (!File.Exists(excelPATH))
	{
		log.Error("The Output Excel File was not available");
		return;
	}
	CheckExcellProcesses(); //To Check EXCEl process is running or not

	//Excel Initializations
	log.Info("Intializing the EXCEL Library");
	log.Info(excelPATH);
	oXL = new Excel.ApplicationClass();
	oWB = oXL.Workbooks.Open(excelPATH, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
	excelSheets = oWB.Worksheets;
	excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(1);
	oSheet = excelWorksheet;
	log.Info(String.Format("Program is writing to {0} File", excelPATH));
	//to Get the XML file
	string[] requiredXMLfiles = getRequiredXMLFiles(fromDate, toDate, "_Excelsheet.xml");

	//Now we have the XML files just to read and write to EXCEL
	foreach (string file in requiredXMLfiles)
	{
		if (File.Exists(file))
		{
			doc.Load(file);
			string OriginalTime = doc.GetElementsByTagName("Time")[0].InnerText;
			XmlNodeList bookList = doc.GetElementsByTagName("HYDR.Database");
			isItFirstRow = true;
			foreach (XmlNode node in bookList)
			{
				CurrentColumn = 2;
				XmlElement bookElement = (XmlElement)node;

				//Reading Values from XML

				string Name = bookElement.GetElementsByTagName("HYDR.Name")[0].InnerText;
				string City = bookElement.GetElementsByTagName("HYDR.City")[0].InnerText;
				string Area = bookElement.GetElementsByTagName("HYDR.Area")[0].InnerText;

				//Writing to Excel file
				if (isItFirstRow)//Table has 3 rows, If first has nothing then no need to check
				{                //Remaining Rows. If first row has the data need to check other rows also
					oSheet.Cells[CurrentRow, CurrentColumn++] = OriginalTime;
					oSheet.Cells[CurrentRow, CurrentColumn++] = Name;
					oSheet.Cells[CurrentRow, CurrentColumn++] = City;
					oSheet.Cells[CurrentRow, CurrentColumn++] = Area;
					CurrentRow++; //Going to next row
					isItFirstRow = false;
					break;
				}
				else
				break;
			}
			else
			{
				oSheet.Cells[CurrentRow, CurrentColumn++] = OriginalTime;
				oSheet.Cells[CurrentRow, CurrentColumn++] = Name;
				oSheet.Cells[CurrentRow, CurrentColumn++] = City;
				oSheet.Cells[CurrentRow, CurrentColumn++] = Area;
				CurrentRow++; //Going to next row
				isItFirstRow = false;
			}
		}
	}//End of Xml Reading///////
}
}
oSheet._Protect("abcd", true, true, true, true);
oWB.Save();

推荐答案

您尝试过:

Did you try:
oSheet.Cells[CurrentRow, CurrentColumn].Locked = False;


这篇关于整张纸张受到保护时如何取消单张exel纸张的保护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆