Java Excel 列号数字与字母互相转换

Java实现的Excel列号数字与字母互相转换功能 主要介绍了Java实现的Excel列号数字与字母互相转换功能,涉及java针对Excel相关数值与字符串操作技巧,需要的朋友可以参考下 立即下载

在工作中Excel解析时,常常需要将列号的字母转换成对应的数字序号。

package test;


public class ExcelColumn {

    public static void main(String[] args) {
        String colstr = "AA";
        int colIndex = excelColStrToNum(colstr, colstr.length());
        System.out.println("'" + colstr + "' column index of " + colIndex);

        colIndex = 26;
        colstr = excelColIndexToStr(colIndex);
        System.out.println(colIndex + " column in excel of " + colstr);

        colstr = "AAAA";
        colIndex = excelColStrToNum(colstr, colstr.length());
        System.out.println("'" + colstr + "' column index of " + colIndex);

        colIndex = 466948;
        colstr = excelColIndexToStr(colIndex);
        System.out.println(colIndex + " column in excel of " + colstr);
    }

    /**
     * Excel column index begin 1
     * @param colStr
     * @param length
     * @return
     */
    public static int excelColStrToNum(String colStr, int length) {
        int num = 0;
        int result = 0;
        for(int i = 0; i < length; i++) {
            char ch = colStr.charAt(length - i - 1);
            num = (int)(ch - 'A' + 1) ;
            num *= Math.pow(26, i);
            result += num;
        }
        return result;
    }

    /**
     * Excel column index begin 1
     * @param columnIndex
     * @return
     */
    public static String excelColIndexToStr(int columnIndex) {
        if (columnIndex <= 0) {
            return null;
        }
        String columnStr = "";
        columnIndex--;
        do {
            if (columnStr.length() > 0) {
                columnIndex--;
            }
            columnStr = ((char) (columnIndex % 26 + (int) 'A')) + columnStr;
            columnIndex = (int) ((columnIndex - columnIndex % 26) / 26);
        } while (columnIndex > 0);
        return columnStr;
    }
}

参考

经典密码体制(上) 头歌 阅读详情

相关推荐

使用LogisticRegression和LightGBM模型对信贷违约进行预测----基于kaggle比赛数据

3.分离数值型变量与类别型变量,发现有些数值型变量因为输入不规范,比如数值中含有字符(28_,_10000_等)被划分为类别型变量 ,比如 'Age','Annual_Income','Num_of_Loan', 'Num_of_Delayed_Payment', 'Changed_Credit_Limit','Credit_Mix','Monthly_Balance', 'Outstanding_Debt' ,'Amount_invested_monthly'等。三、分箱,woe编码,计算IV值。

I_am_a_big_tiger的博客 1682

JAVA将给定的数字 转换成EXCEL里对应列的列号字母

将输入的数字 n 转换为 Excel 中的列号字母。

zfkdiyi的博客 708

Android-S无线模块前瞻

WiFi - mainlane非强制 S 采用反射的方法直接加载wifiservice,直接hook在systemserver上,无编译依赖。gms可以动态替换wifi服务。 R 采用直接启动service的方式,wifiservice仍然map在systemserver上。 WiFi - 11ad接口支持 11ad被wifi联盟商业化为WIGIG,提供短距的60GHZ载波,理论速度为当前5G 11ac的6倍。市面上基本没有手机支持,需要独立的芯片支撑此功能。 传输距离为3m以内,外界d.

头铁的伦的博客 1044

Java实现Excel列号转字母

如题 /** * description: 列号从1开始,如:1 对应 A列,27对应AA列 * @param value Excel列号 */ private static String excelIndexToStr(int value) { // 转26进制 0-25 int calculateValue = value - 1; // 取高位 int high = calculateValue / 26; //

leeo_may的博客 1147

Linux中Hadoop 集群搭建

零、下载Hadoop: http://archive.cloudera.com/cdh5/cdh/5/?tdsourcetag=s_pctim_aiomsg 一、集群规划: 搭建的 hadoop 集群由 3 台服务器组成,分别叫做 master,salve1 和 slave2。其中 master 作为主节点,slave1 和 slave2 作为从节点。 二、网络配置: 1.查看 3 个节点的主机名...

白墨的小白博客 3993

BIOS硬件监控实战:如何手动读取IT8738芯片的温度与风扇数据(附代码)

本文深入探讨了如何绕过操作系统和HWMonitor等监控软件,直接通过寄存器级操作读取IT8738超级I/O芯片的硬件监控数据。文章提供了从动态定位EC空间、构建底层读写函数到解码传感器寄存器映射的完整实战指南,并附有C语言代码示例,帮助开发者理解BIOS硬件监控的底层原理,适用于定制硬件开发与故障诊断。

weixin_29192211的博客 110

Excel 的字母列号与数字互转思路与 Java 实现

很早之前碰到过这个题了,当时是学校的一个 ACM 比赛,很遗憾在赛场上时没有解出来。不过这个题还是蛮有意思的,一次偶然无聊的时候,又想起了这个题,当时莫名就有思路了,很快写出了相应的代码实现。不过思路才是最重要的。 题目 先了解一下这个题是什么意思。用过 Excel 都知道,它是由行和列来组织数据的,行号是从 1 开始的数字,列号则是大写字母,如图 1 所示。 那么众所周知,英文字母只有 26 个,当列数超过 26 列时怎么表示呢? 从上图可以看出,第 27 列是由 AA 表示的,也就是说.

pansong291PS的优快云博客 5219

anaconda navigator 卡在loading application界面一直没有反应解决办法

在打开anaconda navigator 程序的时候,遇到了2个问题。第一个问题:打开的时候弹出提示:There is an instance of Anaconda Navigator already running.第二个问题:程序一直卡在loading application界面一直没有反应。以下是我的解决办法,有效果。

猿小白的博客 4386

转:使用Java将Excel 列号数字与字母互相转换

转载自:http://blog.youkuaiyun.com/u010571844/article/details/46806265 转载内容(有修改): public class ExcelColumn { public static void main(String[] args) { String colstr = "B"; int colIndex ...

总有一天,你的日积月累,会成为别人的望尘莫及 1747

【VibeCoding系列】小白入门指南:模型选择、编辑器选择、项目预定全分析

开箱即用:下载安装就能用,不用配 API Key(也可以自己配)Cmd+K 快速修改:选中代码,按 Cmd+K,直接让 AI 修改Cmd+L 对话:侧边栏聊天,支持引用文件和代码@文件引用:输入 @ 就能引用项目中的文件,AI 自动读取上下文Agent 模式:告诉 AI 一个需求,它自动跨文件修改下载地址cursor.com(免费版有额度限制,足够入门)✅下载 Cursorcursor.com),安装打开✅选一个小项目(个人名片页 or Todo List)✅按照七步工作流开干。

十年老程序猿,AI 疯狂研究专家,前沿硬核知识分享 212

ONVIF协议简介与协议测试工具使用详解

Onvif协议及协议测试工具使用详解

dvlinker的技术专栏 3万+

java数字转换成字母_Java实现的Excel列号数字与字母互相转换功能

本文实例讲述了Java实现的Excel列号数字与字母互相转换功能。分享给大家供大家参考,具体如下:我们在实现对Excel的导入导出的时候,往往需要准确的给用户提示信息,提示到具体的Excel的单元格,这里就需要对Excel的列号进行数字和字母的转换,今天正好用到这个需求,所以就写了一个demo,总结一下:Java实现:package test;/*** Deal with Excel column...

weixin_34551601的博客 658

华为OD机考双机位C卷 - 最左侧冗余覆盖子串 (Java)

华为OD机考双机位C卷 - 最左侧冗余覆盖子串 (Java), 提供Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。

算法大师! 59

java poi 列号 转字母_Java实现的Excel列号数字与字母互相转换功能

本文实例讲述了Java实现的Excel列号数字与字母互相转换功能。分享给大家供大家参考,具体如下:我们在实现对Excel的导入导出的时候,往往需要准确的给用户提示信息,提示到具体的Excel的单元格,这里就需要对Excel的列号进行数字和字母的转换,今天正好用到这个需求,所以就写了一个demo,总结一下:Java实现:package test;/*** Deal with Excel column...

weixin_39563722的博客 428

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

使用Java将Excel 列号数字与字母互相转换

public class ExcelColumn { public static void main(String[] args) { String colstr = "B"; int colIndex = excelColStrToNum(colstr); System.out.println(colstr+"列转换成数字下标:"+...

ZNW9876543210的博客 2699

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Java 导出 Excel 列号数字与字母互相转换工具

package test; /** * Deal with Excel column indexToStr and strToIndex * @author * @version 2015-7-8 * @see */ public class ExcelColumn { public static void main(String[] args) {...

weixin_30322405的博客 224

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

java导出excel为数字型_Java 导出 Excel 列号数字与字母互相转换工具

package test;/*** deal with excel column indextostr and strtoindex* @author* @version 2015-7-8* @see*/public class excelcolumn {public static void main(string[] args) {string colstr = "aa";int colinde...

weixin_26812607的博客 583

java中excel导入mysql,Java将excel中的数据导入到mysql中

我们在实际工作中的一些时候会需要将excel中的数据导入数据库,如果你的数据量成百上千甚至更多,相信一点点ctrlc、ctrlv也不是办法,这里我们以mysql数据库为例,将excel中的数据存入数据库。我的思路是:先将excel中的数据取出来,再把数据传入数据库,操作excel需要jxl.jar,操作数据库可以用最基本的jdbc,需要mysql-connector-java-5.0.8-bin....

weixin_32929205的博客 709

java poi列号转字母_通过Excel列号取得其对应的列字母

在编程中,我们常常利用POI或者其他接口操作Excel文件。当通过列号写公式时,很麻烦。因为Excel公式中,使用列字母形式表示单元格。比如:SUM(B1:B5),下面的方法可以通过Excel列号取得其对应的列字母。这样通过循环列号,得到对应的列字母就可以方便的进行操作不同列了。下面是实现代码。Java实现/*** 获取一列对应的字母。例如:ColumnNum=1,则返回值为A 列号转字母*/pr...

weixin_35890852的博客 3174

java excel单元格数据格式_POI实战-java开发excel详解之单元格各类型数据读取

2.复杂读取2.1 单元格各类型数据读取2.1.1 基本类型在实际工作中,我们处理的Excel数据都不止限于字符型数据,更多的是数字、日期、甚至公式等。下面是单元格类型说明:类型CELL_TYPE_BLANK空值(cell不为空)CELL_TYPE_BOOLEAN布尔CELL_TYPE_ERROR错误CELL_TYPE_FORMULA公式CELL_TYPE_STRING字符串CELL_TYPE_N...

weixin_34310561的博客 1784

获取EXCEL中对应的列英文字母标识符(字母序列/列标题)(JAVA实现)

已经发现更有效的算法,请参考《Excel中列数字与字母的转换(JAVA实现)》如果您有兴趣,可以继续阅读!  最近的一个专案中客户有这么一个需求:读取EXCEL档案的时候,需要做一些处理,但当处理某个单元格时如果发生异常需要记录是哪个单元格导致的异常,并且以列标题(字母+数字的)形式表示是哪个单元格 比如是 第7行第6列的单元格出错,则会记录 "F7 XXXX". 我们都知

Mars_Yuan的专栏 6224

Java poi Excel xls列号数字转字母

最近遇到导出的xls中 列是动态生成的,且单元格中需要用到公式,而xls公式不是用数字列号而是用列字母来表示的,这时需要把数字的列号转成该列对应的字母。因为是按月导出 一个月最多31天,所以刚开始采用的办法是定义一个包含1到31列字母的数组。后来想想这样总不是个办法 万一列数更多 且是不确定的呢。于是研究了下 怎么把xls数字列号转成对应的字母。

lf124的专栏 8086

java 数字与英文字母相互转换

原文地址:http://blog.youkuaiyun.com/u010571844/article/details/46806265一、数字转字母//数字转字母 1-26 : A-Z private String numberToLetter(int num) { if (num <= 0) { return null; } String letter = "";

noName_code的博客 2万+
上一篇: Java POI解析Excel的跨Sheet读取数据验证下拉值
下一篇: Nginx配置上传文件大小上限
白不懂黑的静
博客等级 码龄16年 93粉丝 306原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值