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;
    }
}
相关推荐
yanweijie03176 小时前
对比VLOOKUP、XLOOKUP、INDEX+MATCH三大查找函数
excel
Codiggerworld7 小时前
Vim的语法:删除、复制、粘贴,像说话一样自然
编辑器·vim·excel
Pentane.8 小时前
【数据分析 | 农业项目】蔬菜类商品的自动定价与补货决策 | Tableau & Excel
数据挖掘·数据分析·excel·tableau
happy_baymax11 小时前
Simulink 端口自动生成工具 (v2.1)(EXCEL+m语言)
服务器·matlab·excel·simulink
SunnyDays101111 小时前
如何使用 C# 高效实现 Excel 与 CSV 的互相转换
c#·excel·csv
热爱生活的五柒12 小时前
excel的使用教程
excel
城数派12 小时前
2025年我国省市县三级的平均坡度数据(Excel\Shp格式)
arcgis·信息可视化·数据分析·excel
大佬,救命!!!1 天前
etp中未运行用例顺序的定位及补齐脚本自动化生成
python·学习笔记·excel·自动化脚本·用例整理清洗
专职1 天前
cursor中与vim插件冲突时的配置
编辑器·vim·excel
木易:_/1 天前
【001】EXCEL办公技巧:隔行提取_excel
excel