Open-XML-SDK icon indicating copy to clipboard operation
Open-XML-SDK copied to clipboard

New APIs to facillitate getting started

Open twsouthwick opened this issue 1 year ago • 0 comments

This is a placeholder issue as we revamp some of the docs to identify APIs we should add to better handle common cases that are exposed by nullability analysis. There appears to be a lot of boilerplate to build up a document that requires null checking and then adding parts, etc that we could probably add some helper methods to simplify things.

For example:

Sheets? sheets = workbookPart.Workbook.GetFirstChild<Sheets>();

this could be null, so defensively, we would want something like:

Sheets sheets = workbookPart.Workbook.GetFirstChild<Sheets>() ?? workbookPart.Workbook.AppendChild(new Sheets());

This becomes cumbersome, when we could add something similar to:

Sheets sheets = workbookPart.Workbook.GetFirstChildOrAdd<Sheets>();

Addtional APIs may be helpful here, and so I'm creating this issue to track some of these quality of life related APIs. I think we should also consider identifying patterns for analyzers to catch to move people to these better patterns as well

twsouthwick avatar Nov 01 '23 21:11 twsouthwick