Author Topic: Degree symbol for angles troubles  (Read 584 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 3964
  • C3D user & customizer
Degree symbol for angles troubles
« on: March 11, 2020, 10:16:09 AM »
I have a form with a DataGridView which has a column for angles. I format the angle to display how the user's angle units are set which works just fine. I also allow the user to output the data to a file or a printer. The output to printer looks exactly like it does in the form, the output to a file does as well: ,0.000,S 6110' 24" W,3.580, That is a portion of a line opened in Notepad. However, when the same file is opened in Excel, the angle column has an extra character inserted: S 61°10' 24" W

Now, if I remove that character in Excel, save, close, reopen, it looks just fine and looks the same in Notepad as it did before. So why is Excel treating the initial file differently than the one it saved? In my form's tools to convert the angle from Radians to Degrees it first creates a string like so: DDdMM'SS" then replaces the d with the degree symbol using this:  value = Regex.Replace(value, @"d", @"");

Any suggestions on what I must do to get Excel to not add that to the string?

MarioR

  • Newt
  • Posts: 49
Re: Degree symbol for angles troubles
« Reply #1 on: March 11, 2020, 10:24:08 AM »
Hello JeffM,

the "°" is ANSI display for the UTF8 "".  Check in Notepad++ the coding, it should UTF8. What is your Excel-version? My Excel 2019 reads utf8-file correctly.

regards Mario

huiz

  • Swamp Rat
  • Posts: 856
  • Certified Prof C3D
Re: Degree symbol for angles troubles
« Reply #2 on: March 11, 2020, 10:27:38 AM »
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

Jeff_M

  • King Gator
  • Posts: 3964
  • C3D user & customizer
Re: Degree symbol for angles troubles
« Reply #3 on: March 11, 2020, 10:56:27 AM »
Thanks guys! I'm using Office 365 and Excel was just updated 4 days ago. The client who brought this up is also using Excel 365.

Jeff_M

  • King Gator
  • Posts: 3964
  • C3D user & customizer
Re: Degree symbol for angles troubles
« Reply #4 on: March 11, 2020, 12:50:32 PM »
I was able to correct the output by changing 1 line of code. From this:
Code - C#: [Select]
  1.       using (StreamWriter sw = File.AppendText(filename))
  2.  
to this:
Code - C#: [Select]
  1.       using (StreamWriter sw = new StreamWriter(filename, true, Encoding.UTF8))
  2.  

nobody

  • Swamp Rat
  • Posts: 816
  • .net stuff
Re: Degree symbol for angles troubles
« Reply #5 on: March 15, 2020, 12:23:11 AM »
It's pretty scary when you have to post a question Jeff...I'm convinced very few can solve it if you can't lol ... luckily they are at the swamp :)
« Last Edit: March 15, 2020, 02:05:17 AM by nobody »