首页 > 编程语言 >c#不安装excle创建表格的实例

c#不安装excle创建表格的实例

时间:2023-07-22 11:24:32浏览次数:44  
标签:count 创建表格 sheet c# excel Cells Excel item excle

  使用c#创建excel的示例,刚时给出了不安装excel也可创建excel的方法,需要的朋友可以参考学习网上的列子学习下下


//创建excel
object missing = System.Reflection.Missing.Value;
Excel.Application app = new Excel.Application();
app.Application.Workbooks.Add(true);
Excel.Workbook book = (Excel.Workbook)app.ActiveWorkbook;
Excel.Worksheet sheet = (Excel.Worksheet)book.ActiveSheet;

#region 第一行
sheet.Cells[1, 1] = "登录名(loginID)";
sheet.Cells[1, 2] = "密码(passWord)";
sheet.Cells[1, 3] = "姓(familyName)";
sheet.Cells[1, 4] = "名(firstName)";
sheet.Cells[1, 5] = "性别(gender)";
sheet.Cells[1, 6] = "出生时间(dateofBirth)";
sheet.Cells[1, 7] = "手机号(cellphoneNum)";
sheet.Cells[1, 8] = "身份证号(identityID)";
sheet.Cells[1, 9] = "就职状态(jobStatus)";
sheet.Cells[1, 10] = "公司电话(telephoneNum)";
sheet.Cells[1, 11] = "邮箱(email)";
sheet.Cells[1, 12] = "祖籍(nativeHome)";
sheet.Cells[1, 13] = "毕业学校(graduateSchool)";
sheet.Cells[1, 14] = "专业(major)";
sheet.Cells[1, 15] = "毕业时间(graduateTime)";
sheet.Cells[1, 16] = "学历(education)";
sheet.Cells[1, 17] = "邮编(zipCode)";
sheet.Cells[1, 18] = "地址(address)";
sheet.Cells[1, 19] = "入职时间(entryTime)";
sheet.Cells[1, 20] = "离开时间(leaveTime)";
sheet.Cells[1, 21] = "备注(remarks)";
sheet.Cells[1, 22] = "部门(departmentID)";
sheet.Cells[1, 23] = "职位(JobTypeID";
#endregion

#region 循环写入内容
int count = 1;
foreach (EmployeeInfo_tbl item in enterpriseInfo.Employees)
{
count = count+1;
sheet.Cells[count, 1] = item.loginID;
sheet.Cells[count, 2] = item.passWord;
sheet.Cells[count, 3] = item.familyName;//"姓(familyName)";
sheet.Cells[count, 4] = item.firstName; //"名(firstName)";
sheet.Cells[count, 5] = item.gender; //"性别(gender)";
sheet.Cells[count, 6] = item.dateofBirth; //"出生时间(dateofBirth)";
sheet.Cells[count, 7] = item.cellphoneNum;//"手机号(cellphoneNum)";
sheet.Cells[count, 8] = item.identityID;//"身份证号(identityID)";
sheet.Cells[count, 9] = item.jobStatus;//"就职状态(jobStatus)";
sheet.Cells[count, 10] = item.telephoneNum;//"公司电话(telephoneNum)";
sheet.Cells[count, 11] = item.email;//"邮箱(email)";
sheet.Cells[count, 12] = item.nativeHome;//"祖籍(nativeHome)";
sheet.Cells[count, 13] = item.graduateSchool;// "毕业学校(graduateSchool)";
sheet.Cells[count, 14] = item.major;// "专业(major)";
sheet.Cells[count, 15] = item.graduateTime;//"毕业时间(graduateTime)";
sheet.Cells[count, 16] = item.education;// "学历(education)";
sheet.Cells[count, 17] = item.zipCode;// "邮编(zipCode)";
sheet.Cells[count, 18] = item.address;//"地址(address)";
sheet.Cells[count, 19] = item.entryTime;//"入职时间(entryTime)";
sheet.Cells[count, 20] = item.leaveTime;// "离开时间(leaveTime)";
sheet.Cells[count, 21] = item.remarks;// "备注(remarks)";
sheet.Cells[count, 22] = item.Department.departmentName;// "部门(departmentID)";
sheet.Cells[count, 23] = item.JobType.jobName;// "职位(JobTypeID";
}
#endregion
//保存
//book.SaveCopyAs(_FolderBrowserDialog.SelectedPath + @"\test.xls");
//关闭文件
//book.Close(false, missing, missing);
//退出excel
//app.Quit();

标签:count,创建表格,sheet,c#,excel,Cells,Excel,item,excle
From: https://www.cnblogs.com/yeci/p/17573025.html

相关文章

  • 【大联盟】20230707 xor(xor) CF1456E 【XOR-ranges】
    就我不会*3500/kel题目描述here。题解做法考虑从高位往低位处理,由于有限制的数它的值数确定的,没限制的数值不需要管,因为肯定可以是答案为\(0\)。所以我们考虑区间DP,我们令\(f_{i,l,r,0/1,0/1}\)表示从高往低到第\(i\)位,最左侧\(l\)还有限制,第一个\(0/1\)表示\(x......
  • c#计算点到直线的投影点坐标
    ​ 点在指定直线的投影点,即过点作一垂直于指定直线的直线,与指定直线的交点即为所求。这个问题其实回归到两条垂直直线的交点问题,回到最原始的初中几何知识,复习下首先我们明确下已知条件,指定直线上任一点A,直线斜率k,点C,求点B说到斜率,就有不存在的情况,如图(2),显然这种情况B的横坐标......
  • c#实现一元二次方程求解器示例分享
    ​ c#实现一元二次方程求解器示例,需要的朋友可以参考下usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceWindowsFo......
  • Codeforces Round 886 (Div. 4)
    F.WeWereBothChildren题解:约数我们先利用\(map\)记录\(a_i\)的出现次数然后对\(map\)中的每一个元素的在其所有不超过\(n\)的倍数的位置上都加上对应的贡献时间复杂度:调和级数\(O(nlogn)\)constintN=2e5+10,M=4e5+10;intn;inta[N];map<int,int>......
  • Codeforces Round 886 (Div. 4)
    CodeforcesRound886(Div.4)A-ToMyCritics思路:最大的两个数的和大于等于10则YES#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongtypedefpair<int,int>PII;typedefpair<string,int>PSI;typedefpair<string,string>PSS;cons......
  • #pragma once 指令和 #ifndef 指令
    #pragmaonce指令和#ifndef指令都是用于避免头文件的重复包含,但它们有一些区别和注意事项。1.功能区别:-#pragmaonce:这是一个非标准的预处理指令,它告诉编译器只包含一次当前的头文件。这是一种简单方便的方式,可以避免头文件的多次包含。大多数编译器都支持这个指令,但并非所......
  • 【大联盟】20230703 T2 开心的序列(sequence) 题解 AT_agc049_f 【[AGC049F] Happy Sequ
    zak/bx恐怖zak将这题加强,出到模拟赛。直接把\(A_i,B_i\le10^5,C_i\le5\)变成了\(A_i,B_i,C_i\le10^9\)。非常恐怖。题目描述点击膜拜zhoukangyang。题解重新再理解一遍。我们维护\(p(x)=\sum_i|a_i-x|+|b_i-x|\),那么就相当于要求\(\forallx,p(x)\le0\),也就......
  • Java8、Java11新特性/Stream/MapReduce
    Q:如果题目里出现了java8的特性,然后问题问你下面哪个命令编译无错那么看下是不是有-java-source8-Xlint:all,是的话就选-source8。Q:JDK8中内置了哪些注解?A:@Override(重点)@Deprecated(重点)@SuppressWarnnings(重点)@SafeVarargs(JDK7引入)@FunctionalInterface(JDK8引入)Q:......
  • win11安装docker及应用
    一、win11安装docker在docker官网DownloadDockerDesktop|Docker下载安装。安装后启动,可能碰到图示异常://在cmd输入命令,稍等片刻即好wsl--update二、docker常用命令(在cmd中执行)//安装镜像dockerpull[镜像名称]:[镜像版本]比如安装rabbitmq3.12.2版本,命令为do......
  • 「解题报告」Codeforces Round 886 (Div. 4)
    比赛地址:Dashboard-CodeforcesRound886(Div.4)-Codeforces由于时间太晚了,因此并没有参加比赛,题目都是后来补做的。A.ToMyCriticsProblem-A-Codeforces\(T\)组数据,有\(a,b,c\)三个数,判断是否存在两个数的和\(sum\ge10\)。/*Thecodewaswrittenby......