Solved

Txt output difference in Excel and C#

Posted on 2013-06-21
6
386 Views
Last Modified: 2013-06-24
We have an old excel spreadsheet with vb macros that outputs a text/xml file. This text is used as input to another program. I've written a C#/.net web application that outputs the same text/xml file. When this file is fed to the other program, it crashes. The files are identical to the naked eye, so to speak, but there must be some formatting difference.
What am I looking for?
0
Comment
Question by:allelopath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 15

Accepted Solution

by:
gplana earned 250 total points
ID: 39267023
You can try using some tool like "WinHex" to examine the file at low level and see the differences. Also it could be an encoding character problem (maybe one is using UTF-8 and another is using Latin-1), or it could be caused by some invisible characters like spaces, tabs, line feeds, carry returns, etc...

You can also consider using a tool like windiff to compare both files.

Hope it helps.
0
 
LVL 1

Author Comment

by:allelopath
ID: 39267045
I should have been more explicit ... They look identical in a hex editor, e.g. there is 0D 0A at the end of each line. So the difference is encoding. Is there a default encoding when writing out using an excel vb macro?
0
 
LVL 15

Expert Comment

by:gplana
ID: 39267056
If they are identical in a hex editor, then the problem couldn't be the file because both files have the same content. Try to rename a file to the other and see what happens (maybe the problem is the name of the file?)
0
Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

 
LVL 1

Author Comment

by:allelopath
ID: 39267080
I take back what I said. The files are not different. The file I am generating in C# has 3 characters at the beginning:
EF BB BF      
which apparently specifies UTF-8. So I can do this with XmlWriterSettings:
this.settings.Encoding = Encoding.ASCII;

Open in new window

0
 
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 250 total points
ID: 39267205
Can you post the two files?  or You can use a diff tool like beyond compare to send the differences only, especially at the top of your files.
If the contents are the same usually the difference is the encoding you need to find out the encoding of each file by using a program like Notepad++, just open the file and look for the file properties. Once you have the encoding of your original file then you just need to have the same encoding for your .net generated file.

Another option is to change the other program (that consumes your xml) to handle xml with utf-8 encoding.
0
 
LVL 1

Author Closing Comment

by:allelopath
ID: 39271643
Note that my last comment is the answer.

I tried to accept it as the answer but it looks like there is a bug in EE.
When I check the Your comment box and the Best Solution radio button for my last comment, as well as selecting the 2 posts by the experts (each defaulting to 250pts). I cannot assign points to my comment because there is no point box there and so when I submit, it won't complete saying that each accepted answer must have points.

Chrome Version 27.0.1453.116 m
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question