1 Replies - 7811 Views - Last Post: 26 May 2009 - 04:19 AM Rate Topic: -----

#1 ayceit   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-April 09

want to read all texts from PowerPoint, Excel, Word files in C#

Posted 26 May 2009 - 01:46 AM

hi all,

I'm working on an indexer, and I need to read all texts from PowerPoint, Excel, Word files using C# (visual studio 2008)

I've found a way to read word file using "Microsoft.Office.Interop.Word":
open the doc file, select all text, copy it to clipboard, and get the text from it.

anyway, I can't do the same with PowerPoint or Excel

if there is any other way, I'll be thankful.

thanks...

Is This A Good Question/Topic? 0
  • +

Replies To: want to read all texts from PowerPoint, Excel, Word files in C#

#2 fixo   User is offline

  • D.I.C Regular

Reputation: 85
  • View blog
  • Posts: 335
  • Joined: 10-May 09

Re: want to read all texts from PowerPoint, Excel, Word files in C#

Posted 26 May 2009 - 04:19 AM

View Postayceit, on 26 May, 2009 - 12:46 AM, said:

hi all,

I'm working on an indexer, and I need to read all texts from PowerPoint, Excel, Word files using C# (visual studio 2008)

I've found a way to read word file using "Microsoft.Office.Interop.Word":
open the doc file, select all text, copy it to clipboard, and get the text from it.

anyway, I can't do the same with PowerPoint or Excel

if there is any other way, I'll be thankful.

thanks...



Try something like this
Play around DataFormat, I haven't a time
to check how it will works

	  public static void CopyCell()
		{
			try
			{
				string strFileName = "C:\\PartList.xls";

				Excel.Application xlApp = new Excel.ApplicationClass();
				Excel.Workbook xlWorkBook = null;
				Excel.Worksheet xlWorkSheet = null;
				Excel.Range xlRange = null;
				object misValue = System.Reflection.Missing.Value;

				//' * open existing file *

				xlWorkBook = xlApp.Workbooks.Open(strFileName, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue,
				misValue, misValue, misValue, misValue, misValue);


				xlWorkBook = xlApp.ActiveWorkbook;
				xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
				xlApp.DisplayAlerts = false;
				try
				{
					xlRange = (Excel.Range)xlWorkSheet.UsedRange;
					object curval = xlRange.get_Range("E256", "E256").Value2; //<--cell to copy
					Clipboard.Clear();
					DataObject dob = (DataObject)Clipboard.GetDataObject();
					DataFormats.Format df = DataFormats.GetFormat(DataFormats.StringFormat);
					Clipboard.SetData(df.Name, curval);
					xlWorkBook.Close(false, misValue, misValue);
					xlApp.Quit();
					MessageBox.Show("Try paste into any file");
				}

				catch (System.Exception ex)
				{

					MessageBox.Show(ex.Message + "\\n\\n=======  COPY TO CLIPBOARD ERROR:  ======\\n\\n" + ex.StackTrace);
				}

				finally
				{

					releaseObject(xlRange);
					releaseObject(xlWorkSheet);
					releaseObject(xlWorkBook);
					releaseObject(xlApp);

				}
			}
			catch (System.Exception exl)
			{

				MessageBox.Show(exl.Message + "\\n\\n=======   ERROR TO ACESS EXCEL:  ======\\n\\n" + exl.StackTrace);

			}
		}
		//
		//					 * clean up *
		//
		public static void releaseObject(object obj)
		{
			try
			{

				System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
				obj = null;
			}

			catch (System.Exception ex)
			{
				obj = null;
				MessageBox.Show("Clean Up Memory Error\\n" + ex.ToString());
			}
			finally
			{
				if ((obj != null))
				{
					int pos = GC.GetGeneration(obj);
					GC.Collect(pos);
				}

				else
				{
					GC.Collect();
					GC.WaitForPendingFinalizers();
				}
			}

		}



~'J'~
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1