Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main/HSSF/Record/CFHeaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public CellRangeAddress[] CellRanges
{
if (value == null)
{
throw new ArgumentException("cellRanges must not be null");
throw new ArgumentNullException("cellRanges must not be null");
}
CellRangeAddressList cral = new CellRangeAddressList();
CellRangeAddress enclosingRange = null;
Expand Down
79 changes: 72 additions & 7 deletions main/HSSF/Record/DVRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public class DVRecord : StandardRecord, ICloneable
public const short sid = 0x01BE;
/** Option flags */
private int _option_flags;
/** Title of the prompt box */
/** Title of the prompt box, cannot be longer than 32 chars */
private UnicodeString _promptTitle;
/** Title of the error box */
/** Title of the error box, cannot be longer than 32 chars */
private UnicodeString _errorTitle;
/** Text of the prompt box */
/** Text of the prompt box, cannot be longer than 255 chars */
private UnicodeString _promptText;
/** Text of the error box */
/** Text of the error box, cannot be longer than 255 chars */
private UnicodeString _errorText;
/** Not used - Excel seems to always write 0x3FE0 */
private short _not_used_1 = 0x3FE0;
Expand Down Expand Up @@ -93,6 +93,24 @@ public DVRecord(int validationType, int operator1, int errorStyle, bool emptyCel
Ptg[] formula1, Ptg[] formula2,
CellRangeAddressList regions)
{
// check length-limits
if (promptTitle != null && promptTitle.Length > 32)
{
throw new ArgumentOutOfRangeException("Prompt-title cannot be longer than 32 characters, but had: " + promptTitle);
}
if (promptText != null && promptText.Length > 255)
{
throw new ArgumentOutOfRangeException("Prompt-text cannot be longer than 255 characters, but had: " + promptText);
}

if (errorTitle != null && errorTitle.Length > 32)
{
throw new ArgumentOutOfRangeException("Error-title cannot be longer than 32 characters, but had: " + errorTitle);
}
if (errorText != null && errorText.Length > 255)
{
throw new ArgumentOutOfRangeException("Error-text cannot be longer than 255 characters, but had: " + errorText);
}

int flags = 0;
flags = opt_data_type.SetValue(flags, validationType);
Expand Down Expand Up @@ -390,12 +408,59 @@ public int OptionFlags

public override String ToString()
{
/* @todo DVRecord string representation */
StringBuilder buffer = new StringBuilder();
StringBuilder sb = new StringBuilder();
sb.Append("[DV]\n");
sb.Append(" options=").Append(HexDump.ToHex(_option_flags));
sb.Append(" title-prompt=").Append(FormatTextTitle(_promptTitle));
sb.Append(" title-error=").Append(FormatTextTitle(_errorTitle));
sb.Append(" text-prompt=").Append(FormatTextTitle(_promptText));
sb.Append(" text-error=").Append(FormatTextTitle(_errorText));
sb.Append("\n");
AppendFormula(sb, "Formula 1:", _formula1);
AppendFormula(sb, "Formula 2:", _formula2);
sb.Append("Regions: ");
int nRegions = _regions.CountRanges();
for (int i = 0; i < nRegions; i++)
{
if (i > 0)
{
sb.Append(", ");
}
CellRangeAddress addr = _regions.GetCellRangeAddress(i);
sb.Append('(').Append(addr.FirstRow).Append(',').Append(addr.LastRow);
sb.Append(',').Append(addr.FirstColumn).Append(',').Append(addr.LastColumn).Append(')');
}
sb.Append("\n");
sb.Append("[/DV]");
return sb.ToString();
}

return buffer.ToString();
private static String FormatTextTitle(UnicodeString us)
{
String str = us.String;
if (str.Length == 1 && str[0] == '\0')
{
return "'\\0'";
}
return str;
}

private static void AppendFormula(StringBuilder sb, String label, Formula f)
{
sb.Append(label);

if (f == null)
{
sb.Append("<empty>\n");
return;
}
Ptg[] ptgs = f.Tokens;
sb.Append('\n');
foreach (Ptg ptg in ptgs)
{
sb.Append('\t').Append(ptg.ToString()).Append('\n');
}
}
public override void Serialize(ILittleEndianOutput out1)
{

Expand Down
18 changes: 17 additions & 1 deletion main/HSSF/UserModel/HSSFCellStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ public bool IsHidden
}
}


/// <summary>
/// Get whether the cell's using this style are to be locked
/// </summary>
Expand All @@ -215,6 +214,23 @@ public bool IsLocked
}
}

/// <summary>
/// Turn on or off "Quote Prefix" or "123 Prefix" for the style,
/// which is used to tell Excel that the thing which looks like
/// a number or a formula shouldn't be treated as on.
/// </summary>
/// <value>Is "Quote Prefix" or "123 Prefix" enabled for the cell?</value>
public bool IsQuotePrefixed
{
get
{
return _format._123Prefix;
}
set
{
_format._123Prefix = value;
}
}
/// <summary>
/// Get the type of horizontal alignment for the cell
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions main/HSSF/UserModel/HSSFConditionalFormatting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ public CellRangeAddress[] GetFormattingRanges()
{
return cfAggregate.Header.CellRanges;
}

public void SetFormattingRanges(CellRangeAddress[] ranges)
{
cfAggregate.Header.CellRanges = ranges;
}

/// <summary>
/// Replaces an existing Conditional Formatting rule at position idx.
/// Excel allows to Create up to 3 Conditional Formatting rules.
Expand Down
20 changes: 19 additions & 1 deletion main/HSSF/UserModel/HSSFDataValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public class HSSFDataValidation : IDataValidation
/**
* Constructor which Initializes the cell range on which this object will be
* applied
* @param constraint
*
* @param regions A list of regions where the constraint is validated.
* @param constraint The constraints to apply for this validation.
*/
public HSSFDataValidation(CellRangeAddressList regions, IDataValidationConstraint constraint)
{
Expand Down Expand Up @@ -153,6 +155,14 @@ public bool ShowErrorBox
*/
public void CreatePromptBox(String title, String text)
{
if (title != null && title.Length > 32)
{
throw new ArgumentOutOfRangeException("Prompt-title cannot be longer than 32 characters, but had: " + title);
}
if (text != null && text.Length > 255)
{
throw new ArgumentOutOfRangeException("Prompt-text cannot be longer than 255 characters, but had: " + text);
}
_prompt_title = title;
_prompt_text = text;
this.ShowPromptBox = (/*setter*/true);
Expand Down Expand Up @@ -185,6 +195,14 @@ public String PromptBoxText
*/
public void CreateErrorBox(String title, String text)
{
if (title != null && title.Length > 32)
{
throw new ArgumentOutOfRangeException("Error-title cannot be longer than 32 characters, but had: " + title);
}
if (text != null && text.Length > 255)
{
throw new ArgumentOutOfRangeException("Error-text cannot be longer than 255 characters, but had: " + text);
}
_error_title = title;
_error_text = text;
this.ShowErrorBox = (/*setter*/true);
Expand Down
2 changes: 1 addition & 1 deletion main/HSSF/UserModel/HSSFWorkbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private static String GetWorkbookDirEntryName(DirectoryNode directory)
}

throw new ArgumentException("The supplied POIFSFileSystem does not contain a BIFF8 'Workbook' entry. "
+ "Is it really an excel file?");
+ "Is it really an excel file? Had: " + string.Join("\n", directory.EntryNames));
}

/// <summary>
Expand Down
25 changes: 25 additions & 0 deletions main/POIFS/FileSystem/EntryUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,31 @@ public static void CopyNodes(FilteringDirectoryNode filteredSource,
CopyNodes((DirectoryEntry)filteredSource, (DirectoryEntry)filteredTarget);
}

/**
* Copies nodes from one Directory to the other minus the excepts
*
* @param sourceRoot
* is the source Directory to copy from
* @param targetRoot
* is the target Directory to copy to
* @param excepts
* is a list of Strings specifying what nodes NOT to copy
* @deprecated use {@link FilteringDirectoryNode} instead
*/
[Obsolete("To be removed NPOI 2.8.")]
public static void CopyNodes(DirectoryEntry sourceRoot,
DirectoryEntry targetRoot, List<String> excepts)
{
IEnumerator entries = sourceRoot.Entries;
while(entries.MoveNext())
{
Entry entry = (Entry)entries.Current;
if(!excepts.Contains(entry.Name))
{
CopyNodeRecursively(entry, targetRoot);
}
}
}

/**
* Copies all nodes from one POIFS to the other
Expand Down
17 changes: 17 additions & 0 deletions main/SS/Formula/FormulaShifter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ private FormulaShifter(int srcSheetIndex, int dstSheetIndex)
_mode = ShiftMode.SheetMove;
}

[Obsolete("To be removed NPOI 2.8. deprecated As of 3.14 beta 1 (November 2015), replaced by CreateForRowShift(int, String, int, int, int, SpreadsheetVersion)")]
public static FormulaShifter CreateForRowShift(
int externSheetIndex,
string sheetName,
int firstMovedRowIndex,
int lastMovedRowIndex,
int numberOfRowsToMove)
{
return CreateForRowShift(
externSheetIndex,
sheetName,
firstMovedRowIndex,
lastMovedRowIndex,
numberOfRowsToMove,
SpreadsheetVersion.EXCEL97);
}

public static FormulaShifter CreateForRowShift(
int externSheetIndex,
string sheetName,
Expand Down
8 changes: 8 additions & 0 deletions main/SS/UserModel/CellStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public interface ICellStyle

bool IsLocked { get; set; }

/// <summary>
/// Turn on or off "Quote Prefix" or "123 Prefix" for the style,
/// which is used to tell Excel that the thing which looks like
/// a number or a formula shouldn't be treated as on.
/// Turning this on is somewhat (but not completely, see {@link IgnoredErrorType})
/// like prefixing the cell value with a ' in Excel
/// </summary>
bool IsQuotePrefixed { get; set; }

/**
* get the type of horizontal alignment for the cell
Expand Down
6 changes: 5 additions & 1 deletion main/SS/UserModel/ConditionalFormatting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ public interface IConditionalFormatting
* @return array of <c>CellRangeAddress</c>s. Never <code>null</code>
*/
CellRangeAddress[] GetFormattingRanges();

/**
* Sets the cell ranges the rule conditional formatting must be applied to.
* @param ranges non-null array of <tt>CellRangeAddress</tt>s
*/
void SetFormattingRanges(CellRangeAddress[] ranges);
/**
* Replaces an existing Conditional Formatting rule at position idx.
* Excel allows to create up to 3 Conditional Formatting rules.
Expand Down
21 changes: 12 additions & 9 deletions ooxml/XSSF/Model/StylesTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,11 @@ internal void ReadFrom(XmlDocument xmldoc)
// ===========================================================
// Start of style related Getters and Setters
// ===========================================================
/**
* Get number format string given its id
*
* @param idx number format id
* @return number format code
*/
[Obsolete("deprecated POI 3.14-beta2. Use {@link #getNumberFormatAt(short)} instead.")]

[Obsolete("To be removed NPOI 2.8. GetNumberFormatAt(short) instead.")]
public String GetNumberFormatAt(int idx)
{
return GetNumberFormatAt((short)idx);
return GetNumberFormatAt((short) idx);
}
/**
* Get number format string given its id
Expand Down Expand Up @@ -458,12 +453,20 @@ public int PutFont(XSSFFont font)
return PutFont(font, false);
}

/**
*
* @param idx style index
* @return XSSFCellStyle or null if idx is out of bounds for xfs array
*/
public XSSFCellStyle GetStyleAt(int idx)
{
int styleXfId = 0;

if (xfs.Count == 0) //in case there is no default style
if (idx < 0 || idx >= xfs.Count)
{
//BUG-60343
return null;
}

// 0 is the empty default
if (xfs[idx].xfId > 0)
Expand Down
10 changes: 5 additions & 5 deletions ooxml/XSSF/Streaming/SXSSFCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ public IHyperlink Hyperlink

XSSFHyperlink xssfobj = (XSSFHyperlink)value;
// Assign to us
CellReference reference = new CellReference(RowIndex, ColumnIndex);
xssfobj.GetCTHyperlink().@ref = reference.FormatAsString();
CellReference ref1 = new CellReference(RowIndex, ColumnIndex);
xssfobj.SetCellReference(ref1);

// Add to the lists
((SXSSFSheet)Sheet)._sh.AddHyperlink(xssfobj);
Expand Down Expand Up @@ -697,7 +697,7 @@ private void EnsureFormulaType(CellType type)
{
if (_value.GetType() != CellType.Formula
|| ((FormulaValue)_value).GetFormulaType() != type)
setFormulaType(type);
SetFormulaType(type);
}
/*
* Sets the cell type to type if it is different
Expand All @@ -715,7 +715,7 @@ private void EnsureTypeOrFormulaType(CellType type)
{
if (((FormulaValue)_value).GetFormulaType() == type)
return;
setFormulaType(type); // once a formula, always a formula
SetFormulaType(type); // once a formula, always a formula
return;
}
SetType(type);
Expand Down Expand Up @@ -777,7 +777,7 @@ private void SetType(CellType type)
}
}

private void setFormulaType(CellType type)
private void SetFormulaType(CellType type)
{
Value prevValue = _value;
switch (type)
Expand Down
18 changes: 18 additions & 0 deletions ooxml/XSSF/UserModel/XSSFCellStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,24 @@ public bool IsLocked
}
}

/// <summary>
/// Turn on or off "Quote Prefix" or "123 Prefix" for the style,
/// which is used to tell Excel that the thing which looks like
/// a number or a formula shouldn't be treated as on.
/// </summary>
/// <value>Is "Quote Prefix" or "123 Prefix" enabled for the cell?</value>
public bool IsQuotePrefixed
{
get
{
return _cellXf.quotePrefix;
}
set
{
_cellXf.quotePrefix = value;
}
}

/// <summary>
/// Get the color to use for the right border
/// </summary>
Expand Down
Loading