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 ooxml/POIXMLRelation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public String GetFileName(int index)
public int GetFileNameIndex(POIXMLDocumentPart part)
{
Regex regex = new Regex(_defaultName.Replace("#", "(\\d+)"));
return int.Parse(regex.Match(part.GetPackagePart().PartName.Name).Value);
return int.Parse(regex.Match(part.GetPackagePart().PartName.Name).Groups[1].Value);
//return Integer.valueOf(part.getPackagePart().getPartName().getName().replaceAll(regex, "$1"));
}
/**
Expand Down
15 changes: 14 additions & 1 deletion ooxml/XSSF/UserModel/XSSFSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5101,6 +5101,8 @@ private void ShiftCommentsAndRows(int startRow, int endRow, int n, bool copyRowH
SortedDictionary<XSSFComment, int> commentsToShift =
new SortedDictionary<XSSFComment, int>(new ShiftCommentComparator(n));

IEnumerable<CT_Shape> ctShapes = GetVMLDrawing(false)?.GetItems().OfType<CT_Shape>();

foreach (KeyValuePair<int, XSSFRow> rowDict in _rows)
{
XSSFRow row = rowDict.Value;
Expand All @@ -5123,11 +5125,22 @@ private void ShiftCommentsAndRows(int startRow, int endRow, int n, bool copyRowH
.FindCellComment(cellAddress);
if (oldComment != null)
{
var ctShape = oldComment.GetCTShape();

if (ctShape == null && ctShapes != null)
{
ctShape = ctShapes.FirstOrDefault
(x =>
x.ClientData[0].row[0] == cellAddress.Row &&
x.ClientData[0].column[0] == cellAddress.Column
);
}

XSSFComment xssfComment =
new XSSFComment(
sheetComments,
oldComment.GetCTComment(),
oldComment.GetCTShape());
ctShape);
if (commentsToShift.ContainsKey(xssfComment))
{
commentsToShift[xssfComment] = newrownum;
Expand Down
31 changes: 29 additions & 2 deletions ooxml/XSSF/UserModel/XSSFWorkbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2415,7 +2415,33 @@ public bool CellFormulaValidation

public int AddPicture(byte[] pictureData, PictureType format)
{
int imageNumber = GetAllPictures().Count + 1;
int imageNumber = 1;
List<XSSFPictureData> allPics = (List<XSSFPictureData>)GetAllPictures();

if (allPics.Any())
{
List<int> sortedIndexs = new List<int> { 0 };

sortedIndexs.AddRange
(
allPics
.Select(pic => XSSFPictureData.RELATIONS[(int)pic.PictureType].GetFileNameIndex(pic))
.OrderBy(i => i)
.ToList()
);

int previous = sortedIndexs[0];
for (int index = 1; index < sortedIndexs.Count; index++)
{
if (sortedIndexs[index] > previous + 1)
break;

previous = sortedIndexs[index];
}

imageNumber = previous + 1;
}

XSSFPictureData img = (XSSFPictureData)CreateRelationship(XSSFPictureData.RELATIONS[(int)format], XSSFFactory.GetInstance(), imageNumber, true).DocumentPart;
try
{
Expand All @@ -2428,8 +2454,9 @@ public int AddPicture(byte[] pictureData, PictureType format)
throw new POIXMLException(e);
}
pictures.Add(img);
return imageNumber - 1;

// returns image Index
return allPics.Count - 1;
}

public XSSFWorkbookType WorkbookType
Expand Down