473,669 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel.Applicati on - Issue with text field converted to Scientific notation

1 New Member
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 "91010105212974 61515213" is getting converted to "9.10101E+2 1". 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 1200

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

Similar topics

1
2085
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 they are. I tried to use tostring("f") but it needs to have a precision number after *f* which will cause always have fix number of characters (for example if use f10 then 0.09 is converted to 0.09000000 while I need to show it as 0.09). do...
1
8846
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, and then apply an XSLT to transform the XML into HTML. This works great (or did) until today. I just found out that the "number-format" command in XSLT can't handle scientific notation! So when I try to format these numbers I just get "NaN" on...
0
1695
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 numbers are defined as numeric in the SqlServer Database and are bound to text boxes in the app. In the dataset xml these numbers are defined as decimal. I am using the binding method Format to display the data in scientific notation and Parse to...
7
10910
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
6643
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 // returns 503.51000000000005, rounding error! 4.98e2 + 5.51 // returns 503.51, correct!
2
2759
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 decimal values are written out in scientific notation ("9.984348392E+08"). This wouldn't be a problem except when I try to READ the XML file back into a DataSet I keep getting a System.FormatException saying "Input string was not in a correct format."...
2
7013
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 numbers are defined as numeric in the SqlServer Database and are bound to text boxes in the app. In the dataset's xml these numbers are defined as decimal. I am using the binding method Format to display the data in scientific notation and Parse to...
3
4256
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 control, so it reverts to displaying the value in scientific no- tation (rather stupidly from my standpoint). I don't want that but it seems I can do nothing about it. Any suggestions. Report's RecordSource is a query and this IS a bound control.
3
7209
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 equation from a trendline in excel... If anyone can tell me what this is supposed to mean they can have a cookie* >.>. I know scientific notation, but it seems to me that regular SN is not good enough for microsoft, I mean, why would they put another...
0
1473
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 display linear trendline equation oin graph in "scientific notation" upto 5 decimal places using VBA code. The code which i have written for generating Linear Trendline Equation is: ActiveChart.SeriesCollection(1).Trendlines.Add...
0
8383
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8895
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8809
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7407
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6210
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.