Comments (2)
It seems there is NO option to specify the 'ContentType' when to create the instance of XWPFDocument.
And it would be nice to inject a parameter and let use to specify document type in the constructor.
/**
* Create a new WordProcessingML package and Setup the default minimal content
*/
protected static OPCPackage NewPackage()
{
try {
OPCPackage pkg = OPCPackage.Create(new MemoryStream());
// Main part
PackagePartName corePartName = PackagingUriHelper.CreatePartName(XWPFRelation.DOCUMENT.DefaultFileName);
// Create main part relationship
pkg.AddRelationship(corePartName, TargetMode.Internal, PackageRelationshipTypes.CORE_DOCUMENT);
// Create main document part
pkg.CreatePart(corePartName, XWPFRelation.DOCUMENT.ContentType);
pkg.GetPackageProperties().SetCreatorProperty(DOCUMENT_CREATOR);
return pkg;
}
catch (Exception e)
{
throw new POIXMLException(e);
}
}
and using the 'MACRO_DOCUMENT'
public class XWPFRelation : POIXMLRelation
{
/**
* A map to lookup POIXMLRelation by its relation type
*/
private static Dictionary<String, XWPFRelation> _table = new Dictionary<String, XWPFRelation>();
public static XWPFRelation DOCUMENT = new XWPFRelation(
"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
"/word/document.xml",
null
);
public static XWPFRelation TEMPLATE = new XWPFRelation(
"application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
"/word/document.xml",
null
);
public static XWPFRelation MACRO_DOCUMENT = new XWPFRelation(
"application/vnd.ms-word.document.macroEnabled.main+xml",
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
"/word/document.xml",
null
);
from npoi.
PR is welcomed
from npoi.
Related Issues (20)
- Word Formatting changes after saving with NPOI HOT 1
- How to create scattered chart in excel without markers using NPOI 2.6.2 and C# HOT 1
- Formula calculation exception HOT 1
- Workbook.Write cause OutOfMemory exception while there are 100,000 rows in the Excel file HOT 2
- read xlsx file exception HOT 3
- Adding rows of data into existing xlsx file with pivot tables and charts result with unusable file. HOT 5
- Having Issue while reading a excel file with .xls extension HOT 4
- To set Colors to each column in ColumnChart in NPOI package HOT 1
- XSSF AddPicture Slow HOT 4
- Charts Not Copied HOT 12
- Saving a Workbook and Re-opening It Corrupts the File HOT 13
- Error 0x800A03EC when opening with Excel.Application after saving with NPOI HOT 5
- Overwrite existing Excel results in problem with content HOT 3
- How can protected workbook excel file with npoi HOT 3
- Formula openxml gets corrupted after opened and saved by NPOI 2.7.0 HOT 12
- Excel file is always modified even if only opened for reading HOT 1
- Can't copy sheet's chart when using sheet copy function HOT 1
- System.Runtime.CompilerServices.Unsafe 4.0.41 not found while calling AsSpan HOT 13
- TypeLoadException: “NPOI.XSSF.UserModel.XSSFSheet.RemoveDataValidation” hasn't been implemented in “NPOI.OOXML, Version=2.7.0.0," HOT 1
- Add API for SearchText for xlsx,xls HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from npoi.