473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Excel.Application - Issue with text field converted to Scientific notation

Hi,
I have follwing C# code which opens that tab delimited .txt file and does the saveas to Excel file. Problem what I am running into is some of the text field has value such as "9101010521297461515213" is getting converted to "9.10101E+21". How do I prevent getting converted to scientific notation and leave as text instead using below function ?

Expand|Select|Wrap|Line Numbers
  1. public void SaveTextFileAsExcel(string filefrompath, string filetopath, string newtabname)
  2.         {
  3.             // Excel object references.
  4.             Excel.Application m_objExcel = new Excel.Application();
  5.             Excel.Workbooks m_objBooks = (Excel.Workbooks)m_objExcel.Workbooks;
  6.             Excel._Workbook m_objBook = null;
  7.             Excel.Sheets m_objSheets = null;
  8.             Excel._Worksheet m_objSheet = null;
  9.             // Frequenty-used variable for optional arguments.
  10.             object m_objOpt = System.Reflection.Missing.Value;
  11.             if (filefrompath != "")
  12.             {
  13.                     m_objBooks.OpenText(filefrompath, Excel.XlPlatform.xlWindows,1,
  14.                         Excel.XlTextParsingType.xlDelimited, Excel.XlTextQualifier.xlTextQualifierDoubleQuote,
  15.                         false, true, false, false, false, false,m_objOpt, m_objOpt,
  16.                         m_objOpt, m_objOpt, m_objOpt, m_objOpt, m_objOpt);
  17.  
  18.  
  19.                     m_objBook = m_objExcel.ActiveWorkbook;
  20.                     m_objSheets = m_objBook.Worksheets;
  21.  
  22.                     m_objSheet = (Excel.Worksheet)m_objSheets.get_Item(1);//Get the reference of second worksheet
  23.  
  24.                     string strWorksheetName = m_objSheet.Name;//Get the name of worksheet.
  25.                     if (newtabname != "") { m_objSheet.Name = newtabname; }
  26.  
  27.                     if (filetopath !="")
  28.                     {
  29.                     // Save the text file in the typical workbook format and quit Excel.
  30.                     m_objBook.SaveAs(filetopath, Excel.XlFileFormat.xlWorkbookNormal,
  31.                         m_objOpt, m_objOpt, m_objOpt, m_objOpt, Excel.XlSaveAsAccessMode.xlNoChange, m_objOpt, m_objOpt,
  32.                         m_objOpt, m_objOpt, m_objOpt);
  33.                     } //if (filetopath !="")
  34.             } //if (filefrompath != "")
  35.  
  36.             m_objBook.Close(false, m_objOpt, m_objOpt);
  37.             m_objExcel.Quit();
  38.         } //SaveAsExcel
  39.  
Dec 24 '10 #1
0 1182

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: masoud bayan | last post by:
I have some values in type of double such 0.00009 , 0.0000007, when I want to show them in a text box and convert them to string they are changed to scientific notation while I want to show them as...
1
by: Nick | last post by:
Well, the project I am working on has now come to a screeching halt! I have been developing a program that heavily utilizes ADO.NET record sets. To generate reports, I convert the recordset to XML,...
0
by: Greg | last post by:
I am working on an application that requires working with numbers in scientific notation. I am using SqlServer as the database and I have created strongly typed data adapters and datasets. The...
7
by: Dustan | last post by:
How can I get a number into scientific notation? I have a preference for the format '1 E 50' (as an example), but if it's well known, it works.
9
by: Joe Attardi | last post by:
Hi all, Math is not my strongest area so forgive me if I use some of the wrong terminology. It seems that scientific notation is immune to rounding errors. For example: (4.98 * 100) + 5.51 ...
2
by: rSmoke | last post by:
I have a DataSet that contains a table with about 6 columns of high accuracy decimal values. When I try to write out the DataSet using the WriteXML() function the XML is written fine, but the...
2
by: Greg | last post by:
I am working on an application that requires working with numbers in scientific notation. I am using SqlServer as the database and I have created strongly typed data adapters and datasets. The...
3
by: MLH | last post by:
Textbox on report displays year (1991) in scientific notation if I raise the font size in that control to above 16 points. It seems Access 'thinks' 1991 is too big to display properly in the...
3
by: themadjester | last post by:
http://www.themadjester.com/images/excellesigh.GIF (hover cursor over box to see image of formula that cannot be copied correctly from excel (rabble rabble rabble)) So I made a 6th degree...
0
by: prashantdixit | last post by:
Hi, I am trying to generate Linear Trendline Equation for a graph using VBA in Excel 2007. I am able to do it. However It always generate trendline equation in "General" Format. And i want to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.