26 public partial class WorkbookReader : IPlugInReader
28 private MemoryStream stream;
55 public void Init(MemoryStream stream,
Workbook workbook, IOptions readerOptions)
58 this.Workbook = workbook;
61 this.passwordReader.
Init(PasswordType.WorkbookProtection,
this.readerOptions);
74 XmlDocument xr =
new XmlDocument() { XmlResolver =
null };
75 using (XmlReader reader = XmlReader.Create(stream,
new XmlReaderSettings() { XmlResolver =
null }))
78 foreach (XmlNode node
in xr.DocumentElement.ChildNodes)
80 if (node.LocalName.Equals(
"sheets", StringComparison.OrdinalIgnoreCase) && node.HasChildNodes)
82 GetWorksheetInformation(node.ChildNodes);
84 else if (node.LocalName.Equals(
"bookViews", StringComparison.OrdinalIgnoreCase) && node.HasChildNodes)
86 GetViewInformation(node.ChildNodes);
88 else if (node.LocalName.Equals(
"workbookProtection", StringComparison.OrdinalIgnoreCase))
90 GetProtectionInformation(node);
93 RederPlugInHandler.HandleInlineQueuePlugins(ref stream,
Workbook, PlugInUUID.WorkbookInlineReader);
97 catch (NotSupportedContentException)
103 throw new IOException(
"The XML entry could not be read from the input stream. Please see the inner exception:", ex);
111 private void GetProtectionInformation(XmlNode node)
113 bool lockStructure =
false;
114 bool lockWindows =
false;
117 if (attribute !=
null)
119 int value = ParserUtils.ParseBinaryBool(attribute);
121 lockWindows = value == 1;
124 if (attribute !=
null)
126 int value = ParserUtils.ParseBinaryBool(attribute);
128 lockStructure = value == 1;
130 Workbook.SetWorkbookProtection(
true, lockWindows, lockStructure,
null);
132 if (passwordReader.PasswordIsSet())
134 Workbook.WorkbookProtectionPassword.CopyFrom(passwordReader);
142 private void GetViewInformation(XmlNodeList nodes)
144 foreach (XmlNode node
in nodes)
146 if (node.LocalName.Equals(
"workbookView", StringComparison.OrdinalIgnoreCase))
148 string attribute = ReaderUtils.GetAttribute(node,
"visibility");
149 if (attribute !=
null && ParserUtils.ToLower(attribute) ==
"hidden")
151 this.Workbook.Hidden =
true;
153 attribute = ReaderUtils.GetAttribute(node,
"activeTab");
154 if (!
string.IsNullOrEmpty(attribute))
156 Workbook.AuxiliaryData.SetData(PlugInUUID.WorkbookReader, PlugInUUID.SelectedWorksheetEntity, ParserUtils.ParseInt(attribute));
166 private void GetWorksheetInformation(XmlNodeList nodes)
168 foreach (XmlNode node
in nodes)
170 if (node.LocalName.Equals(
"sheet", StringComparison.OrdinalIgnoreCase))
174 string sheetName = ReaderUtils.GetAttribute(node,
"name",
"worksheet1");
175 int id = ParserUtils.ParseInt(ReaderUtils.GetAttribute(node,
"sheetId"));
176 string relId = ReaderUtils.GetAttribute(node,
"r:id");
177 string state = ReaderUtils.GetAttribute(node,
"state");
179 if (state !=
null && ParserUtils.ToLower(state) ==
"hidden")
183 WorksheetDefinition definition =
new WorksheetDefinition(
id, sheetName, relId)
187 Workbook.AuxiliaryData.SetData(PlugInUUID.WorkbookReader, PlugInUUID.WorksheetDefinitionEntity,
id, definition);
191 throw new IOException(
"The workbook information could not be resolved. Please see the inner exception:", e);