特别注意: range.Text.ToString(); 和 range.Value2.ToString(); 的区别
如果Excell的单元格里面是日期,前面显示2015年05月10日;后面的显示42134
也就是说:Text 和Value2的不同。
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Excel; public partial class dingdan2_Default5 : System.Web.UI.Page
{
string str日期;
string str单号;
string str运费支付方式;
string str收货人;
string str电话;
string str购货单位;
string str收货地址;
string str制单人;
string str销售业务员;
string str财务部;
string str物流货运组;
string str仓储组; string[,] str索引 = new string[,];
string[,] str数据 = new string[,]; protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
((MasterPage)Master).setDaohang("订单管理->导入订单"); }
}
protected void Button1_Click(object sender, EventArgs e)
{
if ((FileUpload1.HasFile) && (null != FileUpload1.PostedFile))
{
this.ListBox1.Items.Clear(); String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions = { ".xls" };
for (int i = ; i < allowedExtensions.Length; i++)
{
if (fileExtension.ToLower() == allowedExtensions[i])
{
this.Session["g_filename"] = FileUpload1.FileName;
this.FileUpload1.SaveAs(Server.MapPath("uploadfiles\\") + FileUpload1.FileName);
this.ListBox1.Items.Insert(, "文件上传成功! " + FileUpload1.FileName);
}
else
{
this.ListBox1.Items.Insert(, "只能上传EXCEL文件!" + FileUpload1.FileName);
} }
}
else
{
this.ListBox1.Items.Insert(, "无法检测到上传的文件!");
} }
//Excel 应用程序对象
Excel.Application ExcelRS;
//Excel 工作簿对象
Excel._Workbook RSbook;
//Excel 工作页对象
Excel._Worksheet RSsheet;
//某一个单元格对象
Excel.Range range; protected void Button2_Click(object sender, EventArgs e)
{
try
{
//第一步:建立Excel应用程序
ExcelRS = new Excel.Application();
this.ListBox1.Items.Insert(, "建立Excel应用程序成功!"); //第二步:建立Excel工作簿
RSbook = (Excel._Workbook)ExcelRS.Workbooks.Open(Server.MapPath("uploadfiles\\")+this.Session["g_filename"].ToString(), Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
this.ListBox1.Items.Insert(, "建立Excel工作簿成功!"); //第三步:设置第一个工作溥
RSsheet = (Excel._Worksheet)RSbook.Sheets.get_Item();
this.ListBox1.Items.Insert(, "建立Excel工作页成功!"); //第四步:读取数据
range = (Excel.Range)RSsheet.get_Range("B2", Type.Missing);
this.str日期 = range.Text.ToString();
this.ListBox1.Items.Insert(,"日期:"+this.str日期); range = (Excel.Range)RSsheet.get_Range("G2", Type.Missing);
this.str单号= range.Value2.ToString();
this.ListBox1.Items.Insert(, "单号:" + this.str单号); range = (Excel.Range)RSsheet.get_Range("B3", Type.Missing);
this.str运费支付方式 = range.Value2.ToString();
this.ListBox1.Items.Insert(, "运费支付方式:" + this.str运费支付方式); range = (Excel.Range)RSsheet.get_Range("D3", Type.Missing);
this.str收货人 = range.Value2.ToString();
this.ListBox1.Items.Insert(, "收货人:" + this.str收货人); range = (Excel.Range)RSsheet.get_Range("G3", Type.Missing);
this.str电话 = range.Value2.ToString();
this.ListBox1.Items.Insert(, "电话:" + this.str电话); range = (Excel.Range)RSsheet.get_Range("B4", Type.Missing);
this.str购货单位 = range.Value2.ToString();
this.ListBox1.Items.Insert(, "购货单位:" + this.str购货单位); range = (Excel.Range)RSsheet.get_Range("B5", Type.Missing);
this.str收货地址 = range.Value2.ToString();
this.ListBox1.Items.Insert(, "收货地址:" + this.str收货地址); range = (Excel.Range)RSsheet.get_Range("B15", Type.Missing);
this.str制单人 = range.Value2.ToString();
this.ListBox1.Items.Insert(, "制单人:" + this.str制单人); range = (Excel.Range)RSsheet.get_Range("E15", Type.Missing);
this.str销售业务员 = range.Value2.ToString();
this.ListBox1.Items.Insert(, "销售业务员:" + this.str销售业务员); range = (Excel.Range)RSsheet.get_Range("I15", Type.Missing);
this.str财务部 = range.Value2.ToString();
this.ListBox1.Items.Insert(, "财务部:" + this.str财务部); range = (Excel.Range)RSsheet.get_Range("B16", Type.Missing);
this.str物流货运组 = range.Value2.ToString();
this.ListBox1.Items.Insert(, "物流货运组:" + this.str物流货运组); range = (Excel.Range)RSsheet.get_Range("E16", Type.Missing);
this.str仓储组 = range.Value2.ToString();
this.ListBox1.Items.Insert(, "仓储组:" + this.str仓储组); for (int i = ; i < ; i++)
{
str索引[i - , ] = "A" + i.ToString();
str索引[i - , ] = "B" + i.ToString();
str索引[i - , ] = "C" + i.ToString();
str索引[i - , ] = "D" + i.ToString();
str索引[i - , ] = "E" + i.ToString();
str索引[i - , ] = "F" + i.ToString();
str索引[i - , ] = "G" + i.ToString();
str索引[i - , ] = "H" + i.ToString();
str索引[i - , ] = "I" + i.ToString();
str索引[i - , ] = "J" + i.ToString();
} //读取数据
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
range = (Excel.Range)RSsheet.get_Range(str索引[i,j], Type.Missing);
str数据[i,j] = range.Text.ToString();
this.ListBox1.Items.Add(i.ToString() + ":" + j.ToString() + "=" + str数据[i, j]);
}
} }
catch (System.Exception ex)
{
this.ListBox1.Items.Insert(,"异常! "+ex.ToString() + "-" +ex.Message +"-"+ex.Source);
}
finally
{
ExcelRS.Quit();
} }
}
特别注意: range.Text.ToString(); 和 range.Value2.ToString(); 的区别的更多相关文章
- range()函数在python3与python2中的区别
range()函数在python3与python2中的区别 - CSDN博客 https://blog.csdn.net/weixin_37579123/article/details/8098038 ...
- JavaScript toString、String和stringify方法区别
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- Exception 的 toString() 方法和 getMessage() 方法的区别
Exception 的 toString() 方法和 getMessage() 方法的区别: 在开发的过程中打印错误日志时尽量使用e.toString() 方法, 因为当错误为空指针时 e.getMe ...
- toString()和Object.prototype.toString.call() 不一样
var arr=[1,2,3];arr.toString()//输出“1,2,3”Object.prototype.toString.call(arr)//输出 "[object Array ...
- python基础-range用法_python2.x和3.x的区别
#range帮助创建连续的数字,通过设置步长来指定不连续 python2.7 #直接就在内存中创建出来(0-99) >>> range(100)[0, 1, 2, 3, 4, 5, ...
- [LeetCode] Range Sum Query - Immutable & Range Sum Query 2D - Immutable
Range Sum Query - Immutable Given an integer array nums, find the sum of the elements between indice ...
- list(range())--------range创建一个list列表 遍历索引range(len()) 和 list(range())创建列表
lst = list(range(15,26)) #注,list(range())用的是小括号哦print(lst)
- leetcode@ [303/304] Range Sum Query - Immutable / Range Sum Query 2D - Immutable
https://leetcode.com/problems/range-sum-query-immutable/ class NumArray { public: vector<int> ...
- Java 异常Exception e中e的getMessage()和toString()以及 e.printStackTrace();方法的区别
Exception e中e的getMessage()和toString()方法的区别: 示例代码1: public class TestInfo { private static String ...
随机推荐
- SqlServer表死锁的解决方法
SqlServer表死锁的解决方法 前些天写一个存储过程,存储过程中使用了事务,后来我把一些代码注释掉来进行调试找错,突然发现一张表被锁住了,原来是创建事务的代码忘记注释掉.本文表锁住了的解决方法 ...
- #define GPFCON (* (volatile unsigned long * )0x56000050 )
int a; int *p; p = &a; *p = 0x100; //a=0x100 p = (int *)0x56000050; *p =0x100; *( ( int * ) 0x56 ...
- setInterval(callback(),time)
最近在写一个需求的时候,出了点小小的问题,在这做个记录. 对于定时函数setInterval()大家应该都不陌生,setInterval(callback(),time)就是说设置一个定时器,每隔ti ...
- MySQL 5.7.18 在centos下安装记录
一个朋友找我如何在linux下安装mysql5.7.18,我稍微整理下了下记录,如下: 下载地址: MySQL5.7.18参数官方网址:https://dev.mysql.com/doc/refman ...
- [置顶]
长谈:关于 View Measure 测量机制,让我一次把话说完
<倚天屠龙记中>有这么一处:张三丰示范自创的太极剑演示给张无忌看,然后问他记住招式没有.张无忌说记住了一半.张三丰又慢吞吞使了一遍,问他记住多少,张无忌说只记得几招了.张三丰最后又示范了一 ...
- ResNet网络结构
MSRA(微软亚洲研究院)何凯明团队的深度残差网络(Deep Residual Network)在2015年的ImageNet上取得冠军,该网络简称为ResNet(由算法Residual命名),层数达 ...
- 前端之JavaScript 补充
1. BOM window location.href = "https://www.sogo.com" location.reload() // 重新加载当前页 location ...
- c printf打印格式
关于小数点位数的举例: <pre lang="c" escaped="true">#include <stdio.h> /* 当fah ...
- BZOJ - 5427:最长上升子序列 (二分&思维)
现在给你一个长度为n的整数序列,其中有一些数已经模糊不清了,现在请你任意确定这些整数的值, 使得最长上升子序列最长.(为何最长呢?因为hxy向来对自己的rp很有信心) Input 第一行一个正整数 ...
- 5款实用的硬盘、SSD固态硬盘、U盘、储存卡磁盘性能测试工具绿色版
http://www.iplaysoft.com/disk-benchmark-tools.html/comment-page-1#comment-149425