问题描述
嗨
我只是在研究导出到Excel的代码.我收到一个与使用C#.NET编程的Excel单元格中的格式相关的查询.
我的要求是,第一行包含要指向以下单元格的列的名称.
我的观点是,第一行包含文本的单元格,在每个单元格中,我想将文本的某些部分保留为粗体,而将另一部分保留为非粗体.
通过描述单元格的范围而不是文本的一部分,我可以使整个单元格文本变为粗体.我经历了谷歌搜索,看到了一些与vba宏相关的东西,但是我却无法使用C#编程通过ASP.nEt完成它.
请为我提供上述查询的解决方案.我将下面的示例代码附在我被打扰的地方.
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet IntroSheet,RespSheet;
字符串name_survey ="Sitemetrics_" + String.Format(&"{0:MM-dd-yy_hh-mm-ss}&",DateTime.UtcNow)+&.xls&";
字符串strXLFileName =& quot; D:\\ Admin \\& quot; + name_survey;
GC.Collect();
oXL =新的Excel.Application();
oXL.Visible = false;
oWB =(Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
//string strCurrentDir = Server.MapPath(&.& quot;)+& quot; \\& quot ;;
int qcount = 0;
Excel._Worksheet []工作表=新的Excel._Worksheet [2];
int jj = 1,ij = 4;
RespSheet =(Excel._Worksheet)oWB.Sheets [1];
RespSheet.Name =& quot;网站指标& quot ;;
int r_indx = 2;
int c_indx = 2;
RespSheet.Cells [1,1] =问题1:您是哪个国家的居民"
RespSheet.Cells [1,2] =问题2:这是您最喜欢的运动"
//从上面的第一个单元格中,我问问题1的文本为粗体,其他文本为非粗体.
问候
sandeep
Hi
I am just working on the Code of the Export to Excel. I got one query related to formatting in Cells of Excel using C#.NET programming.
My requirement is such that 1 row contains names of the columns that are headings to the below cells.
My Point is that first rows cells which contains text, In each cell i want to keep some part of the text as bold and the other part of the text as non-bold.
I am able to make the complete cell text to bold by describing the range of the cells but not the part of the text. I had gone through googling and seen some thing related to vba macros, but some how i am not able to make it get it done through ASP.nEt using C# programming.
Please provide me solution for the above query. I am enclosing the sample code below where i got struck up.
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet IntroSheet, RespSheet;
string name_survey ="Sitemetrics_" + String.Format("{0:MM-dd-yy_hh-mm-ss}", DateTime.UtcNow) + ".xls";
string strXLFileName = "D:\\Admin\\"+name_survey;
GC.Collect();
oXL = new Excel.Application();
oXL.Visible = false;
oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
//string strCurrentDir = Server.MapPath(".") + "\\";
int qcount = 0;
Excel._Worksheet[] Sheet = new Excel._Worksheet[2];
int jj = 1, ij = 4;
RespSheet = (Excel._Worksheet)oWB.Sheets[1];
RespSheet.Name = "Site Metrics";
int r_indx = 2;
int c_indx = 2;
RespSheet.Cells[1,1]="Question 1: you are resident of Which country"
RespSheet.Cells[1, 2] = "Question 2 : which is your favourite sport"
// from the above 1st cell I wat Question 1 text to be bold and the other text to be non bold.
Regards
sandeep
推荐答案
这篇关于关于使用C#.NET在Asp.net中进行Excel导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!