用于生成 Office 文件的 .NET 组件。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

484 lines
17 KiB

8 years ago
/* ====================================================================
Licensed To the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for Additional information regarding copyright ownership.
The ASF licenses this file To You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed To in writing, software
distributed under the License is distributed on an "AS Is" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
/* ================================================================
* About NPOI
8 years ago
* Author: Tony Qu
* Author's email: tonyqus (at) gmail.com
8 years ago
* Author's Blog: tonyqus.wordpress.com.cn (wp.tonyqus.cn)
* HomePage: http://www.codeplex.com/npoi
* Contributors:
8 years ago
*
8 years ago
* ==============================================================*/
namespace Npoi.Core.HPSF
8 years ago
{
using Npoi.Core.HPSF.Wellknown;
using Npoi.Core.Util;
8 years ago
using System;
using System.Collections;
8 years ago
/// <summary>
/// Convenience class representing a DocumentSummary Information stream in a
/// Microsoft Office document.
8 years ago
/// @author Rainer Klute
8 years ago
/// klute@rainer-klute.de
/// @author Drew Varner (Drew.Varner cloSeto sc.edu)
/// @author robert_flaherty@hyperion.com
/// @since 2002-02-09
/// </summary>
[Serializable]
public class DocumentSummaryInformation : SpecialPropertySet
{
/**
* The document name a document summary information stream
* usually has in a POIFS filesystem.
*/
public const string DEFAULT_STREAM_NAME = "\x0005DocumentSummaryInformation";
8 years ago
public override PropertyIDMap PropertySetIDMap {
8 years ago
get
{
return PropertyIDMap.DocumentSummaryInformationProperties;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="DocumentSummaryInformation"/> class.
/// </summary>
/// <param name="ps">A property Set which should be Created from a
/// document summary information stream.</param>
8 years ago
public DocumentSummaryInformation(PropertySet ps) : base(ps) {
8 years ago
if (!IsDocumentSummaryInformation)
throw new UnexpectedPropertySetTypeException
("Not a " + GetType().Name);
}
/// <summary>
/// Gets or sets the category.
/// </summary>
/// <value>The category value</value>
8 years ago
public String Category {
8 years ago
get
{
return GetPropertyStringValue(PropertyIDMap.PID_CATEGORY);
}
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_CATEGORY, value);
}
}
/// <summary>
/// Removes the category.
/// </summary>
8 years ago
public void RemoveCategory() {
8 years ago
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_CATEGORY);
}
/// <summary>
/// Gets or sets the presentation format (or null).
/// </summary>
/// <value>The presentation format value</value>
8 years ago
public String PresentationFormat {
8 years ago
get { return GetPropertyStringValue(PropertyIDMap.PID_PRESFORMAT); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_PRESFORMAT, value);
}
}
/// <summary>
/// Removes the presentation format.
/// </summary>
8 years ago
public void RemovePresentationFormat() {
8 years ago
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_PRESFORMAT);
}
/// <summary>
/// Gets or sets the byte count or 0 if the {@link
/// DocumentSummaryInformation} does not contain a byte count.
/// </summary>
/// <value>The byteCount value</value>
8 years ago
public int ByteCount {
8 years ago
get
{
return GetPropertyIntValue(PropertyIDMap.PID_BYTECOUNT);
}
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_BYTECOUNT, value);
}
}
/// <summary>
/// Removes the byte count.
/// </summary>
8 years ago
public void RemoveByteCount() {
8 years ago
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_BYTECOUNT);
}
/// <summary>
/// Gets or sets the line count or 0 if the {@link
/// DocumentSummaryInformation} does not contain a line count.
/// </summary>
/// <value>The line count value.</value>
8 years ago
public int LineCount {
8 years ago
get
{
return GetPropertyIntValue(PropertyIDMap.PID_LINECOUNT);
}
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_LINECOUNT, value);
}
}
/// <summary>
/// Removes the line count.
/// </summary>
8 years ago
public void RemoveLineCount() {
8 years ago
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_LINECOUNT);
}
/// <summary>
/// Gets or sets the par count or 0 if the {@link
/// DocumentSummaryInformation} does not contain a par count.
/// </summary>
/// <value>The par count value</value>
8 years ago
public int ParCount {
8 years ago
get { return GetPropertyIntValue(PropertyIDMap.PID_PARCOUNT); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_PARCOUNT, value);
}
}
/// <summary>
/// Removes the par count.
/// </summary>
8 years ago
public void RemoveParCount() {
8 years ago
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_PARCOUNT);
}
/// <summary>
/// Gets or sets the slide count or 0 if the {@link
/// DocumentSummaryInformation} does not contain a slide count.
/// </summary>
/// <value>The slide count value</value>
8 years ago
public int SlideCount {
8 years ago
get { return GetPropertyIntValue(PropertyIDMap.PID_SLIDECOUNT); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_SLIDECOUNT, value);
}
}
/// <summary>
/// Removes the slide count.
/// </summary>
8 years ago
public void RemoveSlideCount() {
8 years ago
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_SLIDECOUNT);
}
/// <summary>
/// Gets or sets the note count or 0 if the {@link
/// DocumentSummaryInformation} does not contain a note count
/// </summary>
/// <value>The note count value</value>
8 years ago
public int NoteCount {
8 years ago
get { return GetPropertyIntValue(PropertyIDMap.PID_NOTECOUNT); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_NOTECOUNT, value);
}
}
/// <summary>
/// Removes the note count.
/// </summary>
8 years ago
public void RemoveNoteCount() {
8 years ago
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_NOTECOUNT);
}
/// <summary>
/// Gets or sets the hidden count or 0 if the {@link
/// DocumentSummaryInformation} does not contain a hidden
/// count.
/// </summary>
/// <value>The hidden count value.</value>
8 years ago
public int HiddenCount {
8 years ago
get { return GetPropertyIntValue(PropertyIDMap.PID_HIDDENCOUNT); }
set
{
MutableSection s = (MutableSection)Sections[0];
s.SetProperty(PropertyIDMap.PID_HIDDENCOUNT, value);
}
}
/// <summary>
/// Removes the hidden count.
/// </summary>
8 years ago
public void RemoveHiddenCount() {
8 years ago
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_HIDDENCOUNT);
}
/// <summary>
/// Returns the mmclip count or 0 if the {@link
/// DocumentSummaryInformation} does not contain a mmclip
/// count.
/// </summary>
/// <value>The mmclip count value.</value>
8 years ago
public int MMClipCount {
8 years ago
get { return GetPropertyIntValue(PropertyIDMap.PID_MMCLIPCOUNT); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_MMCLIPCOUNT, value);
}
}
/// <summary>
/// Removes the MMClip count.
/// </summary>
8 years ago
public void RemoveMMClipCount() {
8 years ago
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_MMCLIPCOUNT);
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="DocumentSummaryInformation"/> is scale.
/// </summary>
/// <value><c>true</c> if cropping is desired; otherwise, <c>false</c>.</value>
8 years ago
public bool Scale {
8 years ago
get { return GetPropertyBooleanValue(PropertyIDMap.PID_SCALE); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_SCALE, value);
}
}
/// <summary>
/// Removes the scale.
/// </summary>
8 years ago
public void RemoveScale() {
8 years ago
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_SCALE);
}
/// <summary>
/// Gets or sets the heading pair (or null)
/// </summary>
/// <value>The heading pair value.</value>
8 years ago
public byte[] HeadingPair {
8 years ago
get
{
return (byte[])GetProperty(PropertyIDMap.PID_HEADINGPAIR);
}
8 years ago
set
{
8 years ago
throw new NotImplementedException("Writing byte arrays ");
}
}
/// <summary>
/// Removes the heading pair.
/// </summary>
8 years ago
public void RemoveHeadingPair() {
8 years ago
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_HEADINGPAIR);
}
/// <summary>
/// Gets or sets the doc parts.
/// </summary>
/// <value>The doc parts value</value>
8 years ago
public byte[] Docparts {
8 years ago
get
{
return (byte[])GetProperty(PropertyIDMap.PID_DOCPARTS);
}
8 years ago
set
8 years ago
{
throw new NotImplementedException("Writing byte arrays");
}
}
/// <summary>
/// Removes the doc parts.
/// </summary>
8 years ago
public void RemoveDocparts() {
8 years ago
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_DOCPARTS);
}
/// <summary>
/// Gets or sets the manager (or <c>null</c>).
/// </summary>
/// <value>The manager value</value>
8 years ago
public String Manager {
8 years ago
get { return GetPropertyStringValue(PropertyIDMap.PID_MANAGER); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_MANAGER, value);
}
}
/// <summary>
/// Removes the manager.
/// </summary>
8 years ago
public void RemoveManager() {
8 years ago
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_MANAGER);
}
/// <summary>
/// Gets or sets the company (or <c>null</c>).
/// </summary>
/// <value>The company value</value>
8 years ago
public String Company {
8 years ago
get { return GetPropertyStringValue(PropertyIDMap.PID_COMPANY); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_COMPANY, value);
}
}
/// <summary>
/// Removes the company.
/// </summary>
8 years ago
public void RemoveCompany() {
8 years ago
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_COMPANY);
}
/// <summary>
/// Gets or sets a value indicating whether [links dirty].
/// </summary>
/// <value><c>true</c> if the custom links are dirty.; otherwise, <c>false</c>.</value>
8 years ago
public bool LinksDirty {
8 years ago
get { return GetPropertyBooleanValue(PropertyIDMap.PID_LINKSDIRTY); }
set
{
MutableSection s = (MutableSection)FirstSection;
s.SetProperty(PropertyIDMap.PID_LINKSDIRTY, value);
}
}
/// <summary>
/// Removes the links dirty.
/// </summary>
8 years ago
public void RemoveLinksDirty() {
8 years ago
MutableSection s = (MutableSection)FirstSection;
s.RemoveProperty(PropertyIDMap.PID_LINKSDIRTY);
}
/// <summary>
/// Gets or sets the custom properties.
/// </summary>
/// <value>The custom properties.</value>
8 years ago
public CustomProperties CustomProperties {
8 years ago
get
{
CustomProperties cps = null;
8 years ago
if (SectionCount >= 2) {
8 years ago
cps = new CustomProperties();
Section section = (Section)Sections[1];
IDictionary dictionary = section.Dictionary;
Property[] properties = section.Properties;
int propertyCount = 0;
8 years ago
for (int i = 0; i < properties.Length; i++) {
8 years ago
Property p = properties[i];
long id = p.ID;
8 years ago
if (id != 0 && id != 1) {
8 years ago
propertyCount++;
CustomProperty cp = new CustomProperty(p,
(string)dictionary[id]);
cps.Put(cp.Name, cp);
}
}
if (cps.Count != propertyCount)
8 years ago
cps.IsPure = false;
8 years ago
}
return cps;
}
8 years ago
set
8 years ago
{
EnsureSection2();
MutableSection section = (MutableSection)Sections[1];
IDictionary dictionary = value.Dictionary;
section.Clear();
/* Set the codepage. If both custom properties and section have a
* codepage, the codepage from the custom properties wins, else take the
* one that is defined. If none is defined, take Unicode. */
int cpCodepage = value.Codepage;
if (cpCodepage < 0)
cpCodepage = section.Codepage;
if (cpCodepage < 0)
cpCodepage = CodePageUtil.CP_UNICODE;
8 years ago
value.Codepage = cpCodepage;
section.Codepage = cpCodepage; //add codepage propertyset
section.Dictionary = dictionary; //generate dictionary propertyset
8 years ago
//generate MutableSections
8 years ago
for (IEnumerator i = value.Values.GetEnumerator(); i.MoveNext();) {
8 years ago
Property p = (Property)i.Current;
section.SetProperty(p);
}
}
}
/// <summary>
/// Creates section 2 if it is not alReady present.
/// </summary>
8 years ago
private void EnsureSection2() {
if (SectionCount < 2) {
8 years ago
MutableSection s2 = new MutableSection();
s2.SetFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID2);
AddSection(s2);
}
}
/// <summary>
/// Removes the custom properties.
/// </summary>
8 years ago
public void RemoveCustomProperties() {
8 years ago
if (SectionCount >= 2)
Sections.RemoveAt(1);
else
throw new HPSFRuntimeException("Illegal internal format of Document SummaryInformation stream: second section is missing.");
}
}
}