本文介绍了OpenXML的 - 保护所有表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够保护只是一个表,但是当我试图保护所有表在我的Excel文档,我得到试图追加SheetProtection错误。

如果我理解正确的话,我必须在SheetData后追加SheetProtection。
这里是我的code:

  SheetProtectiond wSheetProtection =新SheetProtection
                           {
                              表= TRUE,
                              对象= TRUE,
                              场景= TRUE,
                              密码= GetSheetPassword(wWorkbookPassword)
                           };的foreach(板材片材wSheet)
{
     WorksheetPart worksheetPart = GetWorkSheetPartBySheetID(M_S preadsheetDocument.WorkbookPart,sheet.Id);
     worksheetPart.Worksheet.InsertAfter(wSheetProtection,worksheetPart.Worksheet.Descendants&所述; SheetData>().LastOrDefault());
}


解决方案

解决每个表创建SheetProtection的istance。

I'm able to protect just one sheet, but when I try to protect all sheets in my Excel Documents I get an error while trying to append the SheetProtection.

If I've understood correctly, I must append SheetProtection after the SheetData.Here is my code:

SheetProtectiond  wSheetProtection = new SheetProtection
                           {
                              Sheet = true,
                              Objects = true,
                              Scenarios = true,
                              Password = GetSheetPassword( wWorkbookPassword )
                           };

foreach( Sheet sheet in wSheet )
{
     WorksheetPart worksheetPart = GetWorkSheetPartBySheetID(m_SpreadsheetDocument.WorkbookPart, sheet.Id );
     worksheetPart.Worksheet.InsertAfter( wSheetProtection, worksheetPart.Worksheet.Descendants<SheetData>( ).LastOrDefault( ) );                      
}
解决方案

solved creating an istance of SheetProtection for each sheets.

这篇关于OpenXML的 - 保护所有表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 09:27