Skip to content

Commit cb072ec

Browse files
authored
Merge pull request #164 from Josh-Curry/vNext
updated PartUriHelper.GetNextSequenceNumber
2 parents aa6ce81 + 9a2aa05 commit cb072ec

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

DocumentFormat.OpenXml/src/Framework/OpenXmlPackage.cs

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,57 @@ internal class PartUriHelper
13841384
private Dictionary<string, int> _sequenceNumbers = new Dictionary<string, int>(20);
13851385
private Dictionary<string, int> _reservedUri = new Dictionary<string, int>();
13861386

1387+
//List of contentTypes that need to have a 1 appended to the name
1388+
//for the first item in the package. Section numbers in comments
1389+
//refer to the ISO/IEC 29500 standard.
1390+
private static readonly HashSet<string> _numberedContentTypes = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
1391+
{
1392+
//11.3 WordprocessingML Parts
1393+
"application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml",
1394+
"application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml",
1395+
//12.3 SpreadsheetML Parts
1396+
"application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml",
1397+
"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml",
1398+
"application/vnd.openxmlformats-officedocument.spreadsheetml.dialogsheet+xml",
1399+
"application/vnd.openxmlformats-officedocument.drawing+xml",
1400+
"application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml",
1401+
"application/vnd.openxmlformats-officedocument.spreadsheetml.dialogsheet+xml",
1402+
"application/vnd.openxmlformats-officedocument.drawing+xml",
1403+
"application/vnd.openxmlformats-officedocument.spreadsheetml.externalLink+xml",
1404+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetMetadata+xml",
1405+
"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml",
1406+
"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheRecords+xml",
1407+
"application/vnd.openxmlformats-officedocument.spreadsheetml.queryTable+xml",
1408+
"application/vnd.openxmlformats-officedocument.spreadsheetml.revisionLog+xml",
1409+
"application/vnd.openxmlformats-officedocument.spreadsheetml.tableSingleCells+xml",
1410+
"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml",
1411+
"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml",
1412+
//13.3 PresentationML Parts
1413+
"application/vnd.openxmlformats-officedocument.presentationml.comments+xml",
1414+
"application/vnd.openxmlformats-officedocument.presentationml.handoutMaster+xml",
1415+
"application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml",
1416+
"application/vnd.openxmlformats-officedocument.presentationml.notesSlide+xml",
1417+
"application/vnd.openxmlformats-officedocument.presentationml.slide+xml",
1418+
"application/vnd.openxmlformats-officedocument.presentationml.slideLayout+xml",
1419+
"application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml",
1420+
"application/vnd.openxmlformats-officedocument.presentationml.slideUpdateInfo+xml",
1421+
"application/vnd.openxmlformats-officedocument.presentationml.tags+xml",
1422+
//14.2 DrawingML Parts
1423+
"application/vnd.openxmlformats-officedocument.drawingml.chart+xml",
1424+
"application/vnd.openxmlformats-officedocument.drawingml.chartshapes+xml",
1425+
"application/vnd.openxmlformats-officedocument.drawingml.diagramColors+xml",
1426+
"application/vnd.openxmlformats-officedocument.drawingml.diagramData+xml",
1427+
"application/vnd.openxmlformats-officedocument.drawingml.diagramLayout+xml",
1428+
"application/vnd.openxmlformats-officedocument.drawingml.diagramStyle+xml",
1429+
"application/vnd.openxmlformats-officedocument.theme+xml",
1430+
"application/vnd.openxmlformats-officedocument.themeOverride+xml",
1431+
//15.2 Shared Parts
1432+
"application/vnd.openxmlformats-officedocument.customXmlProperties+xml",
1433+
"application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings",
1434+
"application/vnd.openxmlformats-officedocument.wordprocessingml.printerSettings",
1435+
"application/vnd.openxmlformats-officedocument.presentationml.printerSettings"
1436+
};
1437+
13871438
public PartUriHelper()
13881439
{
13891440
}
@@ -1415,8 +1466,6 @@ internal Uri GetUniquePartUri(string contentType, Uri parentUri, string targetPa
14151466
string sequenceNumber = this.GetNextSequenceNumber(contentType);
14161467
string path = Path.Combine(targetPath, targetName + sequenceNumber + targetExt);
14171468

1418-
1419-
14201469
Uri uri = new Uri(path, UriKind.RelativeOrAbsolute);
14211470
partUri = PackUriHelper.ResolvePartUri(parentUri, uri);
14221471
// partUri = PackUriHelper.GetNormalizedPartUri(PackUriHelper.CreatePartUri(uri));
@@ -1466,7 +1515,9 @@ private string GetNextSequenceNumber(string contentType)
14661515
else
14671516
{
14681517
this._sequenceNumbers.Add(contentType, 1);
1469-
return "";
1518+
1519+
//Certain contentTypes need to be numbered starting with 1.
1520+
return _numberedContentTypes.Contains(contentType) ? "1" : "";
14701521
}
14711522
}
14721523
}

0 commit comments

Comments
 (0)