Excel导出不会正确显示波斯字符

时间:2015-10-13 06:06:13

标签: mysql excel encoding export persian

在将MySQL表格和视图导出到Excel期间,我遇到了波斯语字符的问题,它们搞砸了这样的事情:

پیاده سازی چند پرداختی مبلغ درصدی

然而,表和列的编码是UTF-8。我想这可能是因为ODBC驱动程序,因为从SQL Server导出到Excel似乎没问题。

1 个答案:

答案 0 :(得分:0)

这是class Book { String Publisher {get; set;} String Title {get; set;} } class ViewModel { var listBooks = new ObservableCollection<Book>(); listBooks.Add(new Book(){Publisher = "RandomHouse", Title = "Title1"}); listBooks.Add(new Book(){Publisher = "RandomHouse", Title = "Title2"}); listBooks.Add(new Book(){Publisher = "Penguin", Title = "Title5"}); ObservableCollection<Book> ListBookItems {get {return listBooks.Orderby(e => e.Publisher).ToList(); } } } <UserControl.Resources> <Style TargetType="ItemsControl" x:Key="ListBookStyle"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <ScrollViewer CanContentScroll="True"> <ItemsPresenter/> </ScrollViewer> </ControlTemplate> </Setter.Value> </Setter> <Setter Property="ItemsPanel"> <Setter.Value> <ItemsPanelTemplate> <VirtualizingStackPanel IsItemsHost="True"/> </ItemsPanelTemplate> </Setter.Value> </Setter> <Setter Property="FontFamily"> <Setter.Value>Consolas</Setter.Value> </Setter> </Style> <DataTemplate DataType="{x:Type models:Book}"> <Grid IsSharedSizeScope="True"> <Grid.ColumnDefinitions> <ColumnDefinition SharedSizeGroup="Publisher" Width="100"/> <ColumnDefinition SharedSizeGroup="Title" Width="100"/> <ColumnDefinition/> </Grid.ColumnDefinitions> <TextBlock HorizontalAlignment="Left" Text="{Binding Publisher}" Grid.Column="0" FontWeight="Bold" Margin="5"/> <TextBlock HorizontalAlignment="Left" Text="{Binding Title}" Grid.Column="1" FontWeight="Bold" Margin="5" /> </Grid> </DataTemplate> <CollectionViewSource x:Key="ListBookItems" Source="{Binding ListBookItems}"> <CollectionViewSource.GroupDescriptions> <PropertyGroupDescription PropertyName="Publisher"/> </CollectionViewSource.GroupDescriptions> </CollectionViewSource> </UserControl.Resources> <DockPanel> <ItemsControl ItemsSource="{Binding Source={StaticResource ListBookItems}}" Style="{StaticResource ListBookStyle}"> <ItemsControl.GroupStyle> <GroupStyle AlternationCount="2"> <GroupStyle.ContainerStyle > <Style TargetType="{x:Type GroupItem}"> <Setter Property="Foreground" Value="#FF444444"/> <Setter Property="Background" Value="#FF000000"/> <!--<Style.Triggers> <Trigger Property="AlternationIndex" Value="0"> <Setter Property="Foreground" Value="#FF444444"/> <Setter Property="Background" Value="#FFD9D9D9"/> </Trigger> <Trigger Property="AlternationIndex" Value="1"> <Setter Property="Foreground" Value="#FF444444"/> <Setter Property="Background" Value="#FFEFEFEF"/> </Trigger> </Style.Triggers>--> </Style> </GroupStyle.ContainerStyle> </GroupStyle> </ItemsControl.GroupStyle> <ItemsControl.Template> <ControlTemplate> <ScrollViewer CanContentScroll="True"> <ItemsPresenter/> </ScrollViewer> </ControlTemplate> </ItemsControl.Template> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel IsItemsHost="True"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> </ItemsControl> </DockPanel>

的Mojibake

这是

的经典案例
  • 客户端中的字节在utf8(正常)中正确编码。
  • 您可能默认与private void resetConnection() { if (mmInputStream != null) { try { mmInputStream.close(); } catch (Exception e) { Log.e(LOG_TAG, "CANNOT CLOSE InputStream", e); } mmInputStream = null; } if (mmOutputStream != null) { try { mmOutputStream.close(); } catch (Exception e) { Log.e(LOG_TAG, "CANNOT CLOSE OutputStream", e); } mmOutputStream = null; } if (mmSocket != null) { try { mmSocket.close(); } catch (Exception e) { Log.e(LOG_TAG, "CANNOT CLOSE mmSocket", e); } mmSocket = null; } } (或پیاده سازی چند پرداختی مبلغ درصدی或...)相关联。 (应该是SET NAMES latin1。)
  • 表格中的列可能是set_charset('latin1'),也可能不是utf8,但应该是这样。

如果您需要修复数据,则需要“两步更改”,例如

CHARACTER SET utf8

其中长度足够大而另一个“......”还有其他任何内容(ALTER TABLE Tbl MODIFY COLUMN col VARBINARY(...) ...; ALTER TABLE Tbl MODIFY COLUMN col VARCHAR(...) ... CHARACTER SET utf8 ...; 等)已经在列上。