I am looking for C# code that will read document file (.doc/.docx) with all formatted words including images, bullets, font with bold/italic/underline, table, header & footer and so on.
Please Help me....
Thanks In Advance.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kurt AmbrosePosted Dec 4, 2020, 9:45 AM
Hello Priti,
There is a quick tutorial of how to display files in a Document Viewer using the LEADTOOLS SDK. This would be able to show Microsoft Word Docx files in the viewer.
https://www.leadtools.com/help/sdk/v21/tutorials/viewers/windows/dotnet/winforms/display-files-in-document-viewer.html
Thanks,
Priyaranjan K SPosted Oct 18, 2015, 11:09 PM
Kiran KPosted Oct 18, 2015, 9:41 PM
float fNumber1 = 12.3f;
Mozart HePosted Oct 18, 2015, 9:34 PM
Aishah khanPosted Oct 18, 2015, 4:09 PM
Marina EberhardtPosted Nov 18, 2014, 7:14 AM
Hi Priti, try this .NET DLL, it will enable you to process Word document with ease.
Here are some C# samples for DOCX processing and C# samples for DOC processing.
Anupam SinghPosted May 26, 2014, 3:06 AM
You can do everything in ms word,ms excel.. b'coz it provides ms office interop assemblies.
All what you have to do is , go and study ms office interoparability.
if you have office 2010
download it here
http://www.microsoft.com/en-us/download/details.aspx?id=3508#SystemRequirements
Hope it helps
Khan Abrar AhmedPosted May 26, 2014, 2:25 AM
u can try like this.
private void ReadMsWord()
{
try
{
//OBJECT OF MISSING "NULL VALUE"
Object miss = System.Reflection.Missing.Value;
//OBJECTS OF FALSE AND TRUE
Object oTrue = true;
object oFalse = false;
Object readOnly = true;
//CREATING OBJECTS OF WORD AND DOCUMENT
Microsoft.Office.Interop.Word.Application oWordApp = new Microsoft.Office.Interop.Word.Application();
// writeLogFile("Document Application Open:::::>> ");
Document docs = null;
// writeLogFile("Document Open:::::>> ");
object path = lblTempFilePathForStream.Text;//ConfigSettings.GetProperty("TempRuleBookFileLoc") + lblFileName.Text;
try
{
if (oWordApp.Documents.Count != 0)
{
oWordApp.Documents.Close(miss, miss, miss);
// writeLogFile("Close any open document:::::>> " );
}
else
{
docs = (Document)oWordApp.Documents.Open(ref path, ref oFalse, ref oTrue, ref oFalse, ref miss, ref miss, ref oTrue, ref miss, ref miss, ref miss, ref miss, ref oFalse, ref oFalse, WdDocumentDirection.wdLeftToRight, ref oTrue, ref miss);
if (docs == null)
writeLogFile("document not open :::::>> ");
else
writeLogFile("Open My document :::::>> " + docs.Name);
}
getParagaphdata(docs);
}
catch (Exception ex)
{
TimeElapsedHandler();
Common.Exceptions.AppException.HandleException(ex);
}
}
catch (Exception ex)
{
TimeElapsedHandler();
Common.Exceptions.AppException.HandleException(ex);
throw ex;
}
}
private void getParagaphdata(Microsoft.Office.Interop.Word.Document docs)
{
try
{
foreach (Microsoft.Office.Interop.Word.Paragraph p in docs.Paragraphs)
{
switch (p.OutlineLevel)
{
case WdOutlineLevel.wdOutlineLevel1:
{
#region Level 1
currentLevel = 1;
if (string.IsNullOrEmpty((p.Range.ListFormat).ListString))
{
}
else
{
}
if (IsDecimal(p.Range.ListFormat.ListString))
{
}
else
{
}
break;
}
case WdOutlineLevel.wdOutlineLevelBodyText:
{
#region Level 10
string text = string.Empty;
text = p.Range.Text;
int count = p.Range.Tables.Count;
string style = ((dynamic)p).style.NameLocal;
if (count == 1)
{
Microsoft.Office.Interop.Word.Table tb = p.Range.Tables[1];
text = checkTableContent(tb, tableString);
}
break;
}
}
}
}
catch (Exception ex)
{
writeLogFile("Document Some Error:::::>> " + ex.ToString());
// Common.Exceptions.AppException.HandleException(0, "Document", ex);
throw ex;
}
}
arron leePosted May 25, 2014, 11:07 PM
Here are some C# code I have ever used to read Word documents in C#.NET platform:
Dhirendra MisraPosted Jan 10, 2014, 12:22 AM
I came across this link which mention why format goes off while copying the content from source to target file.
http://shaunakelly.com/word/styles/formatoftextchanges.html
I think you would need to set format while copying the data. I understand it is not exact solution but you would need to take some other approach.
http://www.c-sharpcorner.com/UploadFile/mgold/CreatingandOpeningMicrosoftDocumentfrom.NETUsingCSharp11262005050939AM/CreatingandOpeningMicrosoftDocumentfrom.NETUsingCSharp.aspx
Priti KumariPosted Jan 9, 2014, 5:00 AM
Dhirendra MisraPosted Jan 9, 2014, 4:21 AM
Refer the links:
http://www.codeproject.com/Articles/3959/Microsoft-Word-Documents-from-ASP-NET
http://www.mindstick.com/Articles/5cd1b721-9b94-4ea0-bd6e-2bb157401069/