WorkSheet.Columns.AutoFit(); 如果 使用 xml生成该如何设置?

Castiel丶Luo 2010-09-06 11:54:05
  writer2.WriteLine("<?xml version=\"1.0\"?>");
writer2.WriteLine("<?mso-application progid=\"Excel.Sheet\"?>");
writer2.WriteLine("<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\"");
writer2.WriteLine(" xmlns:o=\"urn:schemas-microsoft-com:office:office\"");
writer2.WriteLine(" xmlns:x=\"urn:schemas-microsoft-com:office:excel\"");
writer2.WriteLine(" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\"");
writer2.WriteLine(" xmlns:html=\"http://www.w3.org/TR/REC-html40\">");
writer2.WriteLine(" <DocumentProperties xmlns=\"urn:schemas-microsoft-com:office:office\">");
writer2.WriteLine(" <Author>SHELWIN NEE</Author>");
writer2.WriteLine(string.Format(" <Created>{0}T{1}Z</Created>", DateTime.Now.ToString("yyyy-mm-dd"), DateTime.Now.ToString("HH:MM:SS")));
writer2.WriteLine(" <Company>MESNAC</Company>");
writer2.WriteLine(" <Version>11.6408</Version>");
writer2.WriteLine(" </DocumentProperties>");
writer2.WriteLine(" <ExcelWorkbook xmlns=\"urn:schemas-microsoft-com:office:excel\">");
writer2.WriteLine(" <WindowHeight>8955</WindowHeight>");
writer2.WriteLine(" <WindowWidth>11355</WindowWidth>");
writer2.WriteLine(" <WindowTopX>480</WindowTopX>");
writer2.WriteLine(" <WindowTopY>15</WindowTopY>");
writer2.WriteLine(" <ProtectStructure>False</ProtectStructure>");
writer2.WriteLine(" <ProtectWindows>False</ProtectWindows>");
writer2.WriteLine(" </ExcelWorkbook>");
writer2.WriteLine(" <Styles>");
writer2.WriteLine(" <Style ss:ID=\"Default\" ss:Name=\"Normal\">");
writer2.WriteLine(" <Alignment ss:Vertical=\"Bottom\"/>");
writer2.WriteLine(" <Borders/>");
writer2.WriteLine(" <Font/>");
writer2.WriteLine(" <Interior/>");
writer2.WriteLine(" <Protection/>");
writer2.WriteLine(" </Style>");
writer2.WriteLine(" <Style ss:ID=\"s21\">");
writer2.WriteLine(" <Alignment ss:Vertical=\"Bottom\" ss:WrapText=\"1\"/>");
writer2.WriteLine(" </Style>");
writer2.WriteLine(" </Styles>");
writer2.WriteLine(" <Worksheet ss:Name=\"Sheet1\">");
writer2.WriteLine(string.Format(" <Table ss:ExpandedColumnCount=\"{0}\" ss:ExpandedRowCount=\"{1}\" x:FullColumns=\"1\"", numCol.ToString(), numRow.ToString()));
writer2.WriteLine(" x:FullRows=\"0\">");

//确定列的格式
for (numTemp = 0; numTemp != numCol - 1; numTemp++)
{
writer2.WriteLine("<Column ss:AutoFitWidth=\"1\"/>");
}
//导出标题
writer2.WriteLine("<Row ss:AutoFitHeight=\"1\">");
for (numTemp = 0; numTemp != numCol; numTemp++)
{
writer2.Write("<Cell ss:StyleID=\"s21\"><Data ss:Type=\"String\">");
writer2.Write(this.Columns[numTemp].Caption);
writer2.WriteLine("</Data></Cell>");
}
writer2.WriteLine("</Row>");
//导出数据
foreach (DataRow row1 in this.Rows)
{
writer2.WriteLine("<Row>");
for (numTemp = 0; numTemp != numCol; numTemp++)
{
writer2.Write("<Cell ss:StyleID=\"s21\"><Data ss:Type=\"String\">");
writer2.Write(row1[numTemp].ToString());
writer2.WriteLine("</Data></Cell>");
}
writer2.WriteLine("</Row>");
}
writer2.WriteLine(" </Table>");
writer2.WriteLine(" <WorksheetOptions xmlns=\"urn:schemas-microsoft-com:office:excel\">");
writer2.WriteLine(" <Selected/>");
writer2.WriteLine(" <Panes>");
writer2.WriteLine(" <Pane>");
writer2.WriteLine(" <Number>3</Number>");
writer2.WriteLine(" <ActiveRow>1</ActiveRow>");
writer2.WriteLine(" </Pane>");
writer2.WriteLine(" </Panes>");
writer2.WriteLine(" <ProtectObjects>False</ProtectObjects>");
writer2.WriteLine(" <ProtectScenarios>False</ProtectScenarios>");
writer2.WriteLine(" </WorksheetOptions>");
writer2.WriteLine(" </Worksheet>");
writer2.WriteLine(" <Worksheet ss:Name=\"Sheet2\">");
writer2.WriteLine(" <WorksheetOptions xmlns=\"urn:schemas-microsoft-com:office:excel\">");
writer2.WriteLine(" <ProtectObjects>False</ProtectObjects>");
writer2.WriteLine(" <ProtectScenarios>False</ProtectScenarios>");
writer2.WriteLine(" </WorksheetOptions>");
writer2.WriteLine(" </Worksheet>");
writer2.WriteLine(" <Worksheet ss:Name=\"Sheet3\">");
writer2.WriteLine(" <WorksheetOptions xmlns=\"urn:schemas-microsoft-com:office:excel\">");
writer2.WriteLine(" <ProtectObjects>False</ProtectObjects>");
writer2.WriteLine(" <ProtectScenarios>False</ProtectScenarios>");
writer2.WriteLine(" </WorksheetOptions>");
writer2.WriteLine(" </Worksheet>");
writer2.WriteLine("</Workbook>");
writer2 = null;
writer1.Close();


这样设置了列的自适应宽度 但是 只有 列头是自适应了 其他 数据行的 宽度是和列头一致,如何修改 能 使得 列的宽度 和 本列最宽的单元格宽度一致啊
...全文
274 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Castiel丶Luo 2010-09-06
  • 打赏
  • 举报
回复
求解答啊.....

111,083

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧