C++ Set the View Mode, Proofing Language, and Last Saved Date in Word

The view mode, the text language, and the last saved date are display and metadata settings of a document. The view mode determines the layout and the zoom that Word applies when the file is opened, the text language affects the spelling check of the relevant text, and the last saved date is recorded in the file properties for archiving and retrieval. The three settings do not change the body content, yet each of them affects the reading experience and document management.

Spire.Doc for C++ sets the view type and the zoom through Document->GetViewSetup(), specifies the text language through CharacterFormat->SetLocaleIdASCII(), and writes the saved date through BuiltinDocumentProperties->SetLastSaveDate(). All operations run in the local process, and the document does not need to be uploaded to any service.

This article covers three features:

The example uses the Smart Warehouse Management Platform Project Progress Report (Template.docx), which contains a title, three body sections, and a risk table:

The project progress report sample document

Install Spire.Doc for C++

There are two ways to integrate Spire.Doc for C++ into your application. One way is to install it through NuGet; the other is to download the package from our website and copy the libraries into your program. Installing through NuGet is simpler and is the recommended approach.

  • In Visual Studio, open the NuGet Package Manager, search for Spire.Doc.Cpp, and install it.
  • Alternatively, run nuget install Spire.Doc.Cpp in the project directory, and then add the package's include and lib folders to the project.

An integrated project needs to reference the corresponding import library and to ensure that dependency files such as SpireDocCpp.dll and Spire.Doc.Base.dll are present in the run directory. For detailed configuration instructions, refer to How to Integrate Spire.Doc for C++ in a C++ Application.

Set the View Mode and Zoom

The view settings are managed by the ViewSetup object returned by Document->GetViewSetup(). SetDocumentViewType() specifies the layout, SetZoomPercent() specifies the zoom percentage, and SetZoomType() specifies the zoom mode. The example sets the document to Web layout at 150% zoom and uses ZoomType::None to indicate a fixed percentage.

Operation Method Description
Set the layout SetDocumentViewType(DocumentViewType) One of PrintLayout, WebLayout, OutlineLayout, and NormalLayout
Set the zoom percentage SetZoomPercent(int) The common range is 10 to 500
Set the zoom mode SetZoomType(ZoomType) None uses the fixed percentage
Read the current settings GetDocumentViewType(), GetZoomPercent(), GetZoomType() Return the stored values

The detailed steps are as follows.

  • Create a Document object and call LoadFromFile() to load the sample document.
  • Call GetViewSetup() to obtain the view settings object.
  • Call SetDocumentViewType(DocumentViewType::WebLayout) to set the Web layout.
  • Call SetZoomPercent(150) and SetZoomType(ZoomType::None) to set a fixed zoom.
  • Read and output the three settings, and call SaveToFile() to save the document.

The code for setting the view mode and zoom is shown below.

#include <iostream>
#include <string>
#include "Spire/Doc/pch.h"
#ifdef DocumentProperties
#undef DocumentProperties
#endif
#define DocumentProperties DocumentPropertiesA
#include "Spire/Doc/Document.h"
#include "Spire/Doc/DocumentViewType.h"
#include "Spire/Doc/FileFormat.h"
#include "Spire/Doc/Formatting/ViewSetup.h"
#include "Spire/Doc/ZoomType.h"
#include "Spire/Doc/common/h/Stream.h"
using namespace std;
using namespace Spire::Doc;
using namespace Spire::Doc::Common;
using namespace Spire::Doc::Formatting;

int main()
{
    SetConsoleOutputCP(CP_UTF8);

    //Load the project progress report
    intrusive_ptr<Document> document = new Document();
    document->LoadFromFile("Template.docx");

    //Set the Web layout, 150% zoom, and the zoom type
    intrusive_ptr<ViewSetup> view = document->GetViewSetup();
    view->SetDocumentViewType(DocumentViewType::WebLayout);
    view->SetZoomPercent(150);
    view->SetZoomType(ZoomType::None);

    cout << "View type: " << (int)view->GetDocumentViewType() << endl;
    cout << "Zoom percent: " << view->GetZoomPercent() << "%" << endl;
    cout << "Zoom type: " << (int)view->GetZoomType() << endl;

    //Save and close the document
    document->SaveToFile("Output/SetWordViewModes.docx", FileFormat::Docx);
    document->Close();
    return 0;
}

The console output shows that all three settings have been written:

View type: 5
Zoom percent: 150%
Zoom type: 0

When the saved document is opened, the body flows continuously in Web layout at 150% zoom:

The report opened in Web layout at 150% zoom

View Settings Are File-Level Display Properties

The view mode is stored in the settings part of the document, and Word reads the value and displays the file accordingly when it is opened. It does not affect the printed result, and it does not change the pagination. When a file is generated on a server and opened on a client, the layout should be chosen for the usage scenario: use PrintLayout when the output must match a printed page, and use WebLayout when the document is read continuously in a narrow window.

The Zoom Type Takes Precedence over the Percentage

When SetZoomType() is set to a value other than None, Word recalculates the zoom from the window size, and the percentage written by SetZoomPercent() may be overridden. The example sets both SetZoomPercent(150) and SetZoomType(ZoomType::None) so that 150% becomes a fixed value. When only the percentage is adjusted without specifying the zoom mode, the current value of ZoomType should be confirmed first.

Layout and Zoom Are Not Written to the Body

ViewSetup modifies only the display settings of the document; paragraphs, tables, and headers and footers remain as they are. After the example is saved and loaded again, both the body objects and the pagination are unchanged. To adjust the paper size, the margins, or the columns, use Section->GetPageSetup(), which belongs to a different object than the view settings.

Set the Proofing Language of Text

The text language is controlled by three locale IDs of the character format: LocaleIdASCII applies to Western characters, LocaleIdFarEast applies to Chinese, Japanese, and Korean characters, and LocaleIdBi applies to bidirectional text. The example writes a Spanish sentence that lacks accent marks and sets the Western language to 10250, which is Peruvian Spanish. After the setting, Word checks the spelling in that language.

Operation Method Description
Set the Western language SetLocaleIdASCII(short) A Windows locale ID
Read the Western language GetLocaleIdASCII() Returns a short
Set the East Asian language SetLocaleIdFarEast(short) Chinese, Japanese, and Korean
Set the bidirectional language SetLocaleIdBi(short) Arabic, Hebrew, and others

The detailed steps are as follows.

  • Create a Document object and add a section.
  • Add a paragraph in the section and call AppendText() to write the Spanish text.
  • Call GetCharacterFormat() to obtain the character format of that text range.
  • Call SetLocaleIdASCII(10250) to specify Peruvian Spanish.
  • Read and output the locale ID, and call SaveToFile() to save the document.

The code for setting the text language is shown below.

#include <iostream>
#include <string>
#include "Spire/Doc/pch.h"
#ifdef DocumentProperties
#undef DocumentProperties
#endif
#define DocumentProperties DocumentPropertiesA
#include "Spire/Doc/Document.h"
#include "Spire/Doc/Documents/Paragraph.h"
#include "Spire/Doc/Fields/TextRange.h"
#include "Spire/Doc/FileFormat.h"
#include "Spire/Doc/Formatting/CharacterFormat.h"
#include "Spire/Doc/Section.h"
#include "Spire/Doc/common/h/Stream.h"
using namespace std;
using namespace Spire::Doc;
using namespace Spire::Doc::Common;
using namespace Spire::Doc::Documents;
using namespace Spire::Doc::Fields;
using namespace Spire::Doc::Formatting;

int main()
{
    SetConsoleOutputCP(CP_UTF8);

    //Create a document and add a section
    intrusive_ptr<Document> document = new Document();
    intrusive_ptr<Section> section = document->AddSection();
    intrusive_ptr<Paragraph> paragraph = section->AddParagraph();

    //Write Spanish text and set the proofing language to Peruvian Spanish
    intrusive_ptr<TextRange> range = paragraph->AppendText(
        "corrige segun diccionario en ingles");
    range->GetCharacterFormat()->SetLocaleIdASCII(10250);
    cout << "LocaleIdASCII: " << range->GetCharacterFormat()->GetLocaleIdASCII() << endl;

    //Save and close the document
    document->SaveToFile("Output/SetTextLanguage.docx", FileFormat::Docx);
    document->Close();
    return 0;
}

The console output shows that the locale ID has been written to the character format:

LocaleIdASCII: 10250

The Language Setting Applies to a Text Range

SetLocaleIdASCII() is a method of the character format and affects only the TextRange on which it is called. Text appended later in the same paragraph does not automatically inherit the language and must be set again on the new range. The example calls the method on the object returned by AppendText(), so the language covers the whole sentence.

The Locale ID Comes from Windows

10250 is the LCID of Peruvian Spanish. Other common values are 1033 (English, United States), 1036 (French, France), 2052 (Chinese, Simplified), and 1041 (Japanese). When a locale ID that is not installed is passed, Word may fall back to the default proofing language. Chinese text should use SetLocaleIdFarEast(2052); setting only LocaleIdASCII does not change the proofing language of Chinese text.

The Language Setting Does Not Change the Text

The language affects only the spelling and grammar check; it does not change the characters themselves and does not trigger automatic correction. The Spanish text in the example keeps its original spelling, and Word merely checks it against the Peruvian Spanish dictionary. When a spelling check is required before saving, it should be performed through the proofing features of Word; Spire.Doc does not provide a spelling check engine.

Set the Last Saved Date

The last saved date is a built-in document property and is written through BuiltinDocumentProperties->SetLastSaveDate(). The method accepts UTC time; writing local time directly produces a time-zone offset. The example first obtains the current local time, then calculates the offset through TimeZone::GetCurrentTimeZone() and GetUtcOffset(), and finally obtains the UTC time with DateTime::op_Subtraction().

Operation Method Description
Get the current time DateTime::GetNow() Local time
Get the current time zone TimeZone::GetCurrentTimeZone() Returns a TimeZone
Calculate the UTC offset GetUtcOffset(DateTime) Returns a TimeSpan
Subtract the offset DateTime::op_Subtraction(time, span) Local time minus the offset
Write the saved date SetLastSaveDate(DateTime) Accepts UTC time

The detailed steps are as follows.

  • Create a Document object and call LoadFromFile() to load the sample document.
  • Call DateTime::GetNow() to obtain the local time.
  • Call GetCurrentTimeZone() and GetUtcOffset() to calculate the offset of the current time zone.
  • Call DateTime::op_Subtraction() to convert the local time to UTC.
  • Call SetLastSaveDate() to write the value, and call SaveToFile() to save the document.

The code for setting the last saved date is shown below.

#include <iostream>
#include <string>
#include "Spire/Doc/pch.h"
#ifdef DocumentProperties
#undef DocumentProperties
#endif
#define DocumentProperties DocumentPropertiesA
#include "Spire/Doc/BuiltinDocumentProperties.h"
#include "Spire/Doc/Document.h"
#include "Spire/Doc/FileFormat.h"
#include "Spire/Doc/common/h/DateTime.h"
#include "Spire/Doc/common/h/Stream.h"
#include "Spire/Doc/common/h/TimeSpan.h"
#include "Spire/Doc/common/h/TimeZone.h"
using namespace std;
using namespace Spire::Doc;
using namespace Spire::Doc::Common;

//Convert local time to Greenwich Mean Time
intrusive_ptr<DateTime> LocalTimeToGreenwichTime(intrusive_ptr<DateTime> localTime)
{
    intrusive_ptr<TimeZone> zone = TimeZone::GetCurrentTimeZone();
    intrusive_ptr<TimeSpan> offset = zone->GetUtcOffset(localTime);
    return DateTime::op_Subtraction(localTime, offset);
}

int main()
{
    SetConsoleOutputCP(CP_UTF8);

    //Load the project progress report
    intrusive_ptr<Document> document = new Document();
    document->LoadFromFile("Template.docx");

    //Convert the current local time to UTC and write it as the last saved date
    intrusive_ptr<DateTime> localNow = DateTime::GetNow();
    intrusive_ptr<DateTime> utcNow = LocalTimeToGreenwichTime(localNow);
    document->GetBuiltinDocumentProperties()->SetLastSaveDate(utcNow);

    cout << "Local time: " << localNow->ToString() << endl;
    cout << "UTC time written: " << utcNow->ToString() << endl;

    //Save and close the document
    document->SaveToFile("Output/UpdateLastSavedDate.docx", FileFormat::Docx);
    document->Close();
    return 0;
}

The console displays both the local time and the converted UTC time, which differ by 8 hours:

Local time: 2026/12/1 15:36:44
UTC time written: 2026/12/1 7:36:44

After saving, open the Details tab of the file properties; the date last saved is shown as the converted time:

The Date last saved value in the file properties Details tab

SetLastSaveDate Accepts UTC Time

SetLastSaveDate() interprets the passed DateTime as UTC. If DateTime::GetNow() is written directly, the time in the file properties is one time-zone offset ahead of the actual time. The example obtains the offset of the current time zone through GetUtcOffset() and subtracts it from the local time. The offset changes with daylight saving time, so GetUtcOffset() should be called on the current time rather than replaced with a fixed eight hours.

File System Time and Document Properties Differ

When a document is saved, the operating system updates the modification time of the file; SetLastSaveDate() modifies the last saved date recorded inside the document, and the two values come from different sources. The UTC time written by the example is displayed in the Details tab in the local time zone and therefore agrees with the local time. When an archive system needs to sort documents by a uniform time zone, the document property should be taken as the reference.

The Saved Date Is Written by the Save Operation

SetLastSaveDate() modifies the property value in memory, and the value is written into the file only after SaveToFile() is called. If another document is loaded or the property is overwritten before saving, the last assignment prevails. The creation date can be set separately through SetCreateDate().

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.