将word文档转换为pdf
我有一个 RadGridView ,应该导出为 doc、pdf、csv 和 xls 格式。导出到 doc、csv 和 xls 工作正常...但导出到 pdf 格式时出现问题。导出到 pdf 有效,但我隐藏的列仍然显示...
所以我只想通过以下方式将 RadGridView 导出为 pdf:将其导出到 word,然后
以 编程方式将其转换为 pdf...顺便,这是我导出到word的代码。
//export to doc private void Export_Doc(object sender, System.Windows.RoutedEventArgs e) { ExportDialog("doc", "Word", ExportFormat.Html); } private void ExportDialog(string extension, string selectedItem, ExportFormat format) { SaveFileDialog dialog = new SaveFileDialog(); dialog.DefaultExt = extension; dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, selectedItem); dialog.FilterIndex = 1; if (dialog.ShowDialog() == true) { using (Stream stream = dialog.OpenFile()) { GridViewExportOptions exportOptions = new GridViewExportOptions(); exportOptions.Format = format; exportOptions.ShowColumnFooters = true; exportOptions.ShowColumnHeaders = true; exportOptions.ShowGroupFooters = true; RadGridView1.Export(stream, exportOptions); } } }
I have a RadGridView
which should be exported to doc,pdf, csv and xls format. The export to doc, csv and xls works fine... but there's something wrong in exporting it to pdf format. The export to pdf works but the columns that i hide still shows...
So i just thought of exporting the RadGridView
to pdf by: exporting it to word then convert it to pdf programmatically...
By the way, here's my code for exporting to word.
//export to doc private void Export_Doc(object sender, System.Windows.RoutedEventArgs e) { ExportDialog("doc", "Word", ExportFormat.Html); } private void ExportDialog(string extension, string selectedItem, ExportFormat format) { SaveFileDialog dialog = new SaveFileDialog(); dialog.DefaultExt = extension; dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, selectedItem); dialog.FilterIndex = 1; if (dialog.ShowDialog() == true) { using (Stream stream = dialog.OpenFile()) { GridViewExportOptions exportOptions = new GridViewExportOptions(); exportOptions.Format = format; exportOptions.ShowColumnFooters = true; exportOptions.ShowColumnHeaders = true; exportOptions.ShowGroupFooters = true; RadGridView1.Export(stream, exportOptions); } } }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过 OLE 自动化使用 word(注意:word COM 不可重入 - 确保不要从不同线程同时调用它):
Using word via OLE automation (Note: word COM is not re-entrant - make sure not to call this concurrently from different threads):
使用 DevExpress(下面的代码仅适用于 RTF 格式 - 不一定适用于 Word 的所有功能):
Using DevExpress (below code only works with RTF format - which doesn't necessarily work with all Word's functionality):