Word to Google Docs planning, batch compilation, and export helpers built on top of OfficeIMO.Word and OfficeIMO.GoogleWorkspace.
- Build a translation plan before sending anything to Google Docs.
- Export to a new document or replace an existing document via
ExistingFileId. - Apply session-level default Drive and folder placement through
GoogleWorkspaceSessionOptions. - Automatically retry transient Google API failures and surface successful retries in
TranslationReport.
using OfficeIMO.GoogleWorkspace;
using OfficeIMO.Word;
using OfficeIMO.Word.GoogleDocs;
using var document = WordDocument.Create("proposal.docx");
document.AddParagraph("Quarterly business review").SetStyle(WordParagraphStyles.Heading1);
document.AddParagraph("Highlights and next steps.");
var session = new GoogleWorkspaceSession(
new StaticAccessTokenCredentialSource("<google-access-token>"),
new GoogleWorkspaceSessionOptions {
DefaultFolderId = "documents-folder-id",
MaxRetryCount = 5,
RetryBaseDelay = TimeSpan.FromMilliseconds(250),
RetryMaxDelay = TimeSpan.FromSeconds(10),
DiagnosticSink = entry => Console.WriteLine($"{entry.Severity}: {entry.Feature} [{entry.FailureKind}] - {entry.Message}"),
});
var options = new GoogleDocsSaveOptions {
Title = "Quarterly business review",
};
var plan = document.CreateGoogleDocsTranslationPlan(options);
foreach (var notice in plan.Report.Notices) {
Console.WriteLine($"{notice.Severity}: {notice.Feature} - {notice.Message}");
}
var result = await document.ExportToGoogleDocsAsync(session, options);
Console.WriteLine(result.DocumentId);
Console.WriteLine(result.WebViewLink);StaticAccessTokenCredentialSource is provided by OfficeIMO.GoogleWorkspace.
try {
var result = await document.ExportToGoogleDocsAsync(session, options);
Console.WriteLine(result.DocumentId);
} catch (GoogleWorkspaceExportException exception) {
foreach (var entry in exception.ToDiagnosticEntries()) {
Console.WriteLine($"{entry.Severity}: {entry.Feature} [{entry.FailureKind}] - {entry.Message}");
}
}var result = await document.ExportToGoogleDocsAsync(
session,
new GoogleDocsSaveOptions {
Title = "Quarterly business review",
Location = new GoogleDriveFileLocation {
ExistingFileId = "document-id",
},
});- If
Location.FolderIdis omitted, the exporter falls back toGoogleWorkspaceSessionOptions.DefaultFolderId. - If
Location.DriveIdis omitted, the exporter falls back toGoogleWorkspaceSessionOptions.DefaultDriveId. - Successful retries are recorded as
ApiRetriesnotices onGoogleDocumentReference.Report. GoogleWorkspaceSessionOptions.DiagnosticSinkcan stream retry and failure diagnostics while the export is still running.- Failed exports throw
GoogleWorkspaceExportException, which preservesFailureKindand the collectedTranslationReport. - Caller cancellation throws
GoogleWorkspaceExportCanceledException, so cancellation can still be handled separately from timeout or API instability. - API failures prefer parsed Google status and reason codes when Google returns a structured JSON error body.
- Use
CreateGoogleDocsBatch(...)when you want the provider-neutral request model without making network calls.