Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6168949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:46:28+00:00 2026-05-23T22:46:28+00:00

I am using C# and Microsoft Word 12.0 object library to read data from

  • 0

I am using C# and Microsoft Word 12.0 object library to read data from .doc file and then save these content to a text file (This is required by my Project). My .doc file have some tables and I need to read each row and column in such tables.
The reading operations were executed successfully, but the data contains some strange characters (like square ones) as in the attached image

enter image description here

Here is the code I used:

private void btnRead_Click(object sender, EventArgs e)
{
    try
    {
        Microsoft.Office.Interop.Word.ApplicationClass wordObject = new ApplicationClass();
        object file = textBox1.Text; //this is the path
        object nullobject = System.Reflection.Missing.Value;
        Microsoft.Office.Interop.Word.Document docs = wordObject.Documents.Open
            (ref file, ref nullobject, ref nullobject, ref nullobject,
            ref nullobject, ref nullobject, ref nullobject, ref nullobject,
            ref nullobject, ref nullobject, ref nullobject, ref nullobject,
            ref nullobject, ref nullobject, ref nullobject, ref nullobject);

        docs.ActiveWindow.Selection.WholeStory();
        docs.ActiveWindow.Selection.Copy();
        IDataObject data = Clipboard.GetDataObject();
        String allData = "";
        for (int t = 1; t < docs.Tables.Count; t++ )
        {
            Table tbl = docs.Tables[t];
            for (int r = 1; r < tbl.Rows.Count; r++)
            {
                for (int c = 1; c < 3; c++)
                {
                    allData += tbl.Cell(r, c).Range.FormattedText.Text.Trim() + Environment.NewLine;
                }
            }
        }
        txtData.Text = allData;
        saveTextFile(allData);

        docs.Close(ref nullobject, ref nullobject, ref nullobject);
    }
    catch (Exception j)
    {
        MessageBox.Show(j.Message);
    }
}

private void saveTextFile(String data)
{ 
    try
    {
        StreamWriter sw = new StreamWriter(txtOutput.Text.Trim());
        sw.WriteLine(data);
        sw.Flush();
        sw.Close();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.StackTrace);
    }
}

Does anyone have any ideas how can I remove such strange characters, please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:46:29+00:00Added an answer on May 23, 2026 at 10:46 pm

    Well, I’m not very familiar with the doc format specifically, but those boxes (the “strange characters”) are generally displayed when there is a character present that is outside of the printable character set. In this case, since there are always two of them at the end of a line, it might be related to newline characters in the document (or some newline-related parsing error), like \r\n. \r\n is commonly present in many Windows-formatted documents, though whether this is the case in .doc documents is beyond my expertise.

    Of course, removing them should be relatively trivial if you’re happy to hack it. You could simply add a check that just deletes the last two characters of every line. It’s not pretty (and I’d probably recommend against it just on principle) but it appears that it would work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have automated word document creation from templates using the Microsoft Word 12.0 Object
I'm using C# office ( word ) automation by Microsoft Office 12.0 Object Library
How to export pictures in Microsoft Word to TIFF file using Visual Studio Tools
I am using VSTO to fill data into a table in a Microsoft Word
Question I want to programmatically open a RTF file in Microsoft Word using C#.
i am trying to access some information from a running Microsoft Word application using
I have an object created in memory using Microsoft.Office.Interop and Microsoft.Office.Word and with all
I am currently in the process of creating API documentation using Microsoft Word 2007
I'm trying to start Microsoft word using QProcess as following: QString program = WINWORD.EXE;
I am using Microsoft Access 2007 to move and massage some data between two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.