Excel 处理values文件中dimen 的数值问题

比如<dimen name="px11">11.0dp</dimen> 是在一个格子里的,如何将它拆分并操作呢?如果是一整个文件都要修改呢, 写这样的文件的话应该有对应的代码实现,一个java代码就可以实现,这个具体代码我们放在最后,除此之外还有没有别的方法呢,可以用Excel来处理这个问题.

要在 Excel 中将包含 <dimen> 标签的整行文本(例如 <dimen name="px11">11.0dp</dimen>)进行拆分并将数值部分乘以 2,可以按照以下步骤操作:

1.Excel操作

步骤 1:拆分文本

  1. 复制原始数据到 Excel 的某一列,例如 A 列。

  2. 使用 Excel 的"分列"功能

    • 选择包含数据的列(例如,A 列)。
    • 在 Excel 菜单中,选择"数据" -> "分列"。
    • 选择"分隔符"选项,点击"下一步"。
    • 选择"其他",并在输入框中输入 ">",然后点击"完成"。
    • 这将数据拆分为多列,<dimen name="px11"11.0dp</dimen> 分别在 A 列和 B 列中。

步骤 2:提取并修改数值

  1. 提取数值部分

    • 在 C 列中使用公式提取数值部分:

      =LEFT(B2, FIND("dp", B2)-1)

    • 这会提取并显示 B 列中的数值部分,例如 11.0

  2. 将数值乘以 2

    • 在 D 列中,将提取出来的数值乘以 2:

      =C2*2

步骤 3:重新组合文本

  1. 组合修改后的数值和原始文本

    • 在 E 列中组合新的数值和原始的前后部分:

      =A2 & ">" & D2 & "dp</dimen>"

    • 这将生成类似于 <dimen name="px11">22.0dp</dimen> 的新字符串。

  2. 复制并粘贴新值

    • 将 E 列的新字符串复制并粘贴回 A 列(可以使用"选择性粘贴" -> "值"来替换原有数据)。

最终结果

按照以上步骤,你就可以在 Excel 中批量修改 <dimen> 标签中数值部分,并保持标签的格式不变。

如上所示.

2.java代码实现

复制代码
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;

public class MakeXml {
    private final static String rootPath = "D:\\work-space\\android\\dome\\MyApplication\\app\\src\\main\\res\\values-sw{0}dp\\";

    private final static float dw = 320f;
    private final static String DtemplateDp = "<dimen name=\"dimen_dp_{0}\">{1}dp</dimen>\n";
    private final static String DtemplateSp = "<dimen name=\"dimen_sp_{0}\">{1}sp</dimen>\n";
    public static void main(String[] args) {
        makeString(320);
        makeString(340);
        makeString(360);
        makeString(400);
        makeString(480);
        makeString(520);
        makeString(600);
        makeString(720);
        makeString(820);
        makeString(1080);
    }

    public static void makeString(int w) {

        StringBuffer sb = new StringBuffer();
        sb.append("<resources>");
        float cellw = w / dw;
        for (int i = 1; i <= 450; i++) {
            sb.append(DtemplateDp.replace("{0}", i + "").replace("{1}",
                    change(cellw * i) + ""));
            if (i<50) {
                sb.append(DtemplateSp.replace("{0}", i + "").replace("{1}",
                        change(cellw * i) + ""));
            }
        }
        sb.append("</resources>");
        String path = rootPath.replace("{0}", w + "");
        File rootFile = new File(path);
        if (!rootFile.exists()) {
            rootFile.mkdirs();
        }
        File layxFile = new File(path + "dimens_"+ w +".xml");
        try {
            PrintWriter pw = new PrintWriter(new FileOutputStream(layxFile));
            pw.print(sb.toString());
            pw.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }

    public static float change(float a) {
        int temp = (int) (a * 100);
        return temp / 100f;
    }
}
相关推荐
勇太的数分之旅1 小时前
Excel大厂自动化报表实战(互联网金融-数据分析周报制作上)
金融·数据分析·自动化·excel·数据可视化
勇太的数分之旅1 小时前
Excel大厂自动化报表实战(互联网金融-数据分析周报制作中)
金融·数据分析·自动化·excel·数据可视化
一晌小贪欢3 小时前
【Python办公】使用pandas批量读取csv保存为Excel
python·excel·pandas·读取excel·python办公·excel转csv
小志开发4 小时前
Excel VBA入门指南:解锁开发工具与编写你的第一个程序
microsoft·数据分析·excel
_oP_i4 小时前
优化 Excel 文件可以提升文件性能、减少文件大小并加快计算速度
excel
Charlotte_jc4 小时前
完美解决openpyxl保存Excel丢失图像/形状资源的技术方案
开发语言·python·excel·openpyxl
板栗栗-74 小时前
Excel词典(xllex.dll)文件丢失或损坏导致功能异常?别慌!专业修复策略来了!
excel·dll·dll修复·dll错误·dll缺失
开开心心就好16 小时前
电脑扩展屏幕工具
java·开发语言·前端·电脑·php·excel·batch