---
title: "docFormat(from:documentAttributes:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsattributedstring/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.

## Declaration

```swift
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 doc://com.apple.foundation/documentation/Foundation/NSAttributedString/DocumentAttributeKey/documentType.

## Return Value

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

## Discussion

Discussion Raises an rangeException if any part of range lies beyond the end of the receiver’s characters.

## See Also

### Exporting the string as data

- [data(from:documentAttributes:)](foundation/nsattributedstring/data(from:documentattributes:).md)
- [fileWrapper(from:documentAttributes:)](foundation/nsattributedstring/filewrapper(from:documentattributes:).md)
- [rtf(from:documentAttributes:)](foundation/nsattributedstring/rtf(from:documentattributes:).md)
- [rtfd(from:documentAttributes:)](foundation/nsattributedstring/rtfd(from:documentattributes:).md)
- [rtfdFileWrapper(from:documentAttributes:)](foundation/nsattributedstring/rtfdfilewrapper(from:documentattributes:).md)
