Skip to content

DocumentFormat.OpenXml

reference
1 min readUpdated

Kind: Service

Source: Pams/API/Pams.API/Pams.API.csproj (line 1)

Part of: Pams

NuGet package dependency

DocumentFormat.OpenXml is a NuGet package dependency in the Pams API project for reading and writing Office Open XML document formats. The API uses it when processing legacy-format document files such as spreadsheets, word-processing documents, and presentations.

Diagram

mermaid
sequenceDiagram
    participant Client
    participant PamsAPI as Pams API
    participant OpenXml as DocumentFormat.OpenXml
    participant Document as Office Document

    Client->>PamsAPI: Upload or request document processing
    PamsAPI->>OpenXml: Open, read, or create document
    OpenXml->>Document: Parse or write Open XML content
    Document-->>OpenXml: Document data
    OpenXml-->>PamsAPI: Processed document result
    PamsAPI-->>Client: Return response or document file

Usage

ts
async function downloadProcessedDocument(documentId: string) {
  const response = await fetch(`/api/documents/${documentId}/export`, {
    method: "POST",
    headers: {
      Accept: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
    },
  });

  if (!response.ok) {
    throw new Error("Document export failed");
  }

  const file = await response.blob();
  const url = URL.createObjectURL(file);

  window.open(url, "_blank");
}

AI Coding Instructions

  • Keep DocumentFormat.OpenXml references in the Pams API project; browser code should call API endpoints instead of processing Open XML files directly.
  • Dispose document streams and Open XML document instances after reading or writing files.
  • Validate uploaded document types before passing streams to Open XML processing code.
  • Preserve existing document parts and relationships when editing files to avoid corrupting legacy-format documents.

Was this page helpful?

Download as PDF