<!--
{
  "availability" : [
    "macOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSAttributedString/docFormat(from:documentAttributes:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSAttributedString(im)docFormatFromRange:documentAttributes:"
  },
  "title" : "docFormat(from:documentAttributes:)"
}
-->

# docFormat(from:documentAttributes:)

Returns a data object that contains a Microsoft Word–format stream corresponding to the characters and attributes within the specified range.

```
func docFormat(from range: NSRange, documentAttributes dict: [NSAttributedString.DocumentAttributeKey : Any] = [:]) -> Data?
```

## Parameters

`range`

The range.

`dict`

A required dictionary specifying the document attributes. The dictionary contains values from `Document Types` and must at least contain [`documentType`](/documentation/Foundation/NSAttributedString/DocumentAttributeKey/documentType).

## Return Value

Returns a data object containing the attributed string as a Microsoft Word doc file.

## Discussion

Raises an [`rangeException`](/documentation/Foundation/NSExceptionName/rangeException) if any part of `range` lies beyond the end of the receiver’s characters.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)