如何用Excel来帮你写代码

有时候,我们在书写代码的时候需要处理一些具有重复性的数据,比如,我要定义一个枚举,来源如下:


如何用Excel来帮你写代码_第1张图片
image.png

这时候一个个地敲就有些慢了。这时候就该祭出我们的Excel了。
首先,把内容复制后,贴入Excel


如何用Excel来帮你写代码_第2张图片
image.png

然后使用Data->Text To Columns,中文版的话是数据->分列,把它分割成单个元素。


如何用Excel来帮你写代码_第3张图片
image.png

这里我们选固定长度,因为当前这种情况用固定长度拆分更容易。
如何用Excel来帮你写代码_第4张图片
image.png

不过在许多其他的情况下,我们一般常用的是用各种分隔符来切分。
拆分好之后,调整一下。现在每列一种数据了,我们插入几列,并输入其他的内容,比如枚举的名称和括号:


如何用Excel来帮你写代码_第5张图片
image.png

然后,在最后一列,用函数 & 符号连接所有的元素。


如何用Excel来帮你写代码_第6张图片
image.png

最后,直接贴到代码中:

    public enum PageSegmentMode {
        OSD_ONLY(0),//Orientation and script detection (OSD) only.
        AUTO_SEG_WITH_OSD(1),//Automatic page segmentation with OSD.
        AUTO_SEG_NO_OSD(2),//Automatic page segmentation, but no OSD, or OCR.
        FULLY_AUTO_NO_OSD(3),//Fully automatic page segmentation, but no OSD. (Default)
        SINGLE_COLUMN_WITH_VARIABLE_SIZE(4),//Assume a single column of text of variable sizes.
        SINGLE_BLOCK_WITH_VERTICAL_TXT(5),//Assume a single uniform block of vertically aligned text.
        SINGLE_BLOCK_TXT(6),//Assume a single uniform block of text.
        SINGLE_TXT_LINE(7),//Treat the image as a single text line.
        SINGLE_WORD(8),//Treat the image as a single word.
        SINGLE_WORD_IN_CIRCLE(9),//Treat the image as a single word in a circle.
        SINGLE_CHAR(10),//Treat the image as a single character.
        SPARSE_TXT_AS_MUCH_AS_POSSIBLE(11),//Sparse text. Find as much text as possible in no particular order.
        SPARSE_TXT_WITH_OSD(12),//Sparse text with OSD.
        RAW_LINE(13),//Raw line. Treat the image as a single text line, bypassing hacks that are Tesseract-specific.

        private int value;

        PageSegmentMode(int value) {
            this.value = value;
        }
        }

或者,我们可以直接把JavaDoc也给它加上。单独选中每一行之后,点击插入,就会在每一行之前插入一行。然后把javadoc所需的内容放上去。


如何用Excel来帮你写代码_第7张图片
image.png
/**Orientation and script detection (OSD) only. */
        OSD_ONLY (0),
        /**Automatic page segmentation with OSD. */
        AUTO_SEG_WITH_OSD (1),
        /** Automatic page segmentation, but no OSD, or OCR. */
        AUTO_SEG_NO_OSD (2),
        /** Fully automatic page segmentation, but no OSD. (Default) */
        FULLY_AUTO_NO_OSD (3),
        /**Assume a single column of text of variable sizes. */
        SINGLE_COLUMN_WITH_VARIABLE_SIZE (4),
        /**Assume a single uniform block of vertically aligned text. */
        SINGLE_BLOCK_WITH_VERTICAL_TXT (5),
        /**Assume a single uniform block of text. */
        SINGLE_BLOCK_TXT (6),
        /**Treat the image as a single text line. */
        SINGLE_TXT_LINE (7),
        /**Treat the image as a single word. */
        SINGLE_WORD (8),
        /**Treat the image as a single word in a circle. */
        SINGLE_WORD_IN_CIRCLE (9),
        /**Treat the image as a single character. */
        SINGLE_CHAR (10),
        /**Sparse text. Find as much text as possible in no particular order. */
        SPARSE_TXT_AS_MUCH_AS_POSSIBLE (11),
        /**Sparse text with OSD. */
        SPARSE_TXT_WITH_OSD (12),
        /**Raw line. Treat the image as a single text line, bypassing hacks that are Tesseract-specific. */
        RAW_LINE (13)

之后整理一下格式,javadoc就好了。

你可能感兴趣的:(如何用Excel来帮你写代码)