将 Java 代码格式化为 Word/RTF

发布于 2024-08-04 17:28:35 字数 56 浏览 0 评论 0原文

我需要格式化java代码以放入Word文档中。是否有任何程序可以通过关键字突出显示等来执行此操作?

I need to format java code to put into a Word document. Are there any programs that will do this with keyword highlighting, etc. ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

虐人心 2024-08-11 17:28:35

当我从 IDE (Eclipse) 复制/粘贴时,格式会随之而来。

您可能需要首先关闭“标记出现次数”。

When I copy/paste from my IDE (Eclipse), the formatting comes along for the ride.

You'll probably want to turn off "Mark Occurrences" first.

少钕鈤記 2024-08-11 17:28:35

这是一个迟到的回复,但由于这是一个非常具体的要求,我无论如何都会发表我的评论。

您可以使用 Docmosis 以编程方式执行此操作,假设您希望程序在 Java 中运行(而不仅仅是在文档中显示 java )并可以在程序运行的地方安装 OpenOffice。该过程将是:

  1. 创建一个 doc 或 odt 文件,该文件将
    充当模板(设置字体,
    位置、桌子等)并将有
    您想要的位置的占位符
    插入代码示例
  2. 将 docmosis 添加到您的 java 项目
    并编写代码进行初始化
    Docmosis,注册模板,
    然后用你的渲染文档
    选定的 Java 代码。
  3. 目前,Docmosis FieldRenderers
    可以为您的数据添加下划线或斜体
    就这样,但渲染是
    目前应用于整个
    场地。所以这不会让你
    有一个字段可以满足您的所有需求
    java文本并单独突出显示
    词,但还有一些其他的
    你可以使用的技巧来获得
    有用/有趣的结果(例如
    将您的数据分成单独的
    字段并让 Docmosis 渲染
    字段不同)。

您指定为数据的“java 代码”文本将使用模板中的字体和布局属性插入到模板中。渲染器将​​有机会覆盖特定的格式。

This is a late reply but since it's quite a specific requirement I'll post my comment anyway.

You can do this programmatically with Docmosis assuming you want the program to be running in Java (not just showing java in documents) and can install OpenOffice where the program runs. The process would be:

  1. Create a doc or odt file that will
    act as a template (setting fonts,
    position, tables etc) and will have
    a placeholder for where you want to
    insert the code sample
  2. Add docmosis to your java project
    and write the code to initialise
    Docmosis, register the template,
    then render document with your
    selected Java code.
  3. Currently, Docmosis FieldRenderers
    can underline or italicize your data
    as it goes, but the rendering is
    currently applied to the entire
    field. So this wouldn't let you
    have a single field for all your
    java text and individually highlight
    words, but there are a few other
    tricks that you could employ to get
    useful/interesting results (such as
    splitting your data into separate
    fields and letting Docmosis render
    the fields differently).

The "java code" text that you specify as data will be inserted into your template using the font and layout properties in the template. The renderer will have a chance to override specific formatting.

守护在此方 2024-08-11 17:28:35

你可以直接复制然后粘贴到word文档中。我也在使用 OS X。我只是工作得很好。我正在上传它在word中的样子的屏幕截图。

在此处输入图像描述

You can just copy and then paste it to the word document. I am using OS X as well. I just works fine. I am uploading the screenshot of how it looks in word.

enter image description here

箜明 2024-08-11 17:28:35

我正在使用 Easy Code Formatter此处:如何做您以 MS Word 保留格式和语法突出显示显示代码片段吗?

它是一个 Office 加载项。您可以选择多个主题,启用/禁用行编号/突出显示矩形中的行。它允许您选择编码样式 / 并具有快速格式化按钮。相当整洁。

要求您拥有 Office 2013 或更高版本。

在此处输入图像描述

I'm using Easy Code Formatter as called out here: How do you display code snippets in MS Word preserving format and syntax highlighting?

It's an Office add-in. You can select multiple themes, enable / disable line numbering / highlight lines in rectangles. It allows you to select the coding style / and has a quick formatting button. Pretty neat.

Requires you to have Office 2013 or beyond.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文