Solved

Txt output difference in Excel and C#

Posted on 2013-06-21
6
368 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
  • 3
  • 2
6 Comments
 
LVL 15

Accepted Solution

by:
gplana earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:allelopath
Comment Utility
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 35

Assisted Solution

by:Miguel Oz
Miguel Oz earned 250 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now