读取本地excel发短信

package com.cmcc.zysoft.sellmanager.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream; import javax.annotation.Resource; import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label; import com.cmcc.zysoft.sellmanager.service.SysLBSService;
import com.cmcc.zysoft.sellmanager.util.CMPPSenderUtil; /**
*
* 类说明:
*
* @创建时间 2014-3-17 下午1:52:55
* @创建人: cmzcheng
* @邮箱:cmzcheng@gmail.com
*/
public class ExcelOperate { @Resource
private SysLBSService sysLBSService; public static void main(String[] args) { jxl.Workbook readwb = null;
try { // 构建Workbook对象, 只读Workbook对象 // 直接从本地文件创建Workbook InputStream instream = new FileInputStream("D:/sms.xls"); readwb = Workbook.getWorkbook(instream); // Sheet的下标是从0开始 // 获取第一张Sheet表 Sheet readsheet = readwb.getSheet(0); // 获取Sheet表中所包含的总行数 int rsRows = readsheet.getRows(); // 获取指定单元格的对象引用 for (int i = 0; i < rsRows; i++) {
String mobile= readsheet.getCell(0, i).getContents();
String login_url = readsheet.getCell(1, i).getContents();
String serviceName = readsheet.getCell(2, i).getContents();
sendSms(mobile, login_url, serviceName);
System.out.println(serviceName + " ," + mobile + "," + login_url);
}
//利用已经创建的Excel工作薄,创建新的可写入的Excel工作薄 jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(new File( "d:/短信发送列表.xls"), readwb); //读取第一张工作表 jxl.write.WritableSheet ws = wwb.getSheet(0); //获得第一个单元格对象 jxl.write.WritableCell wc = ws.getWritableCell(0, 0); //判断单元格的类型, 做出相应的转化 if (wc.getType() == CellType.LABEL) { Label l = (Label) wc; l.setString("新姓名"); } //写入Excel对象 wwb.write(); wwb.close(); } catch (Exception e) { e.printStackTrace(); } finally { readwb.close(); } } @SuppressWarnings("static-access")
public static boolean sendSms(String phone, String login_url,
String serviceName) {
boolean ls = getPhoneName(phone.substring(0, 3));
CMPPSenderUtil cmp = new CMPPSenderUtil();
try {
if (ls) {// 如果是中国移动的号码
cmp.sendMsg(phone, getContent(phone, login_url, serviceName));
} else {// 表示的是移网
cmp.sendDifferenceNetMsg(phone,
getContent(phone, login_url, serviceName));
} return true;
} catch (Exception e) {
// TODO: handle exception
return false;
} } /**
*
* @param phone
* phone
* @return String
*/
public static String getContent(String phone, String loginURL,
String qiyeTtitle) {
return "您好!" + qiyeTtitle
+ "系统已于3月15日启用域名访问啦,您单位专有网址为+ loginURL+ " ,登录帐号和密码不变,请去试试吧";
} public static boolean getPhoneName(String phoneName) {
String strings = "134,135,136,137,138,139,150,151,152,157,158,159,187,188,182,147,183,184";
boolean flg = strings.contains(phoneName);
return flg;
} }
 
写的一个读取本地excel然后发短信的代码,记录下在此

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

上一篇:【代码笔记】iOS-请求去掉url中的空格


下一篇:hive插入数据-单条