本文整理汇总了C#中Worksheet.Pictures方法的典型用法代码示例。如果您正苦于以下问题:C# Worksheet.Pictures方法的具体用法?C# Worksheet.Pictures怎么用?C# Worksheet.Pictures使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Worksheet
的用法示例。
在下文中一共展示了Worksheet.Pictures方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertPicture
/// <summary>
/// 将图片插入到指定的单元格位置。
/// 注意:图片必须是绝对物理路径 /// </summary>
/// <param name="RangeName">单元格名称,例如:B4</param>
/// <param name="PicturePath">要插入图片的绝对路径。</param>
public static void InsertPicture(Range m_objRange, string PicturePath, Worksheet m_objSheet )
{
object missing = System.Reflection.Missing.Value;
// m_objRange.Select();
Microsoft.Office.Interop.Excel.Pictures pics = (Microsoft.Office.Interop.Excel.Pictures)m_objSheet.Pictures(missing);
var pic = pics.Insert(PicturePath, missing);
pic.Left = m_objRange.Left;
pic.Top = m_objRange.Top;
}
示例2: WriteDataToTheSpecifiedRangeForPdf
private int WriteDataToTheSpecifiedRangeForPdf(System.Data.DataTable dt, Range range, int rowount, int itemPerPage, Worksheet XLsheet, int rowcout, string companyName, int columnScape)
{
int iRow;
int iCol;
rowount = 1;
int excelSheetRow = rowount;
int pageSize = itemPerPage;
var totalPages = 0;
if (dt.Rows.Count%pageSize == 0)
{
totalPages = dt.Rows.Count / pageSize;
}
else
{
totalPages = (dt.Rows.Count / pageSize)+1;
}
for (int i = 0; i < totalPages; i++)
{
#region Main Header
var headerRange1 = XLsheet.Range[XLsheet.Cells[excelSheetRow, 1], XLsheet.Cells[(excelSheetRow + 3), 6]]; //rowount + pageSize * i
headerRange1.Font.Bold = true;
headerRange1.Font.Size = 16;
//headerRange1.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
// headerRange1.Borders.Color = System.Drawing.ColorTranslator.ToOle(Color.Black);
headerRange1.Merge(Type.Missing);
headerRange1.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
string picPath = System.Web.HttpContext.Current.Server.MapPath("../Images/report-logo.png");
object missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.Range picPosition = headerRange1;//GetPicturePosition(); // retrieve the range for picture insert
Microsoft.Office.Interop.Excel.Pictures p = XLsheet.Pictures(missing) as Microsoft.Office.Interop.Excel.Pictures;
Microsoft.Office.Interop.Excel.Picture pic = null;
pic = p.Insert(picPath, missing);
pic.Left = Convert.ToDouble(picPosition.Left);
pic.Top = picPosition.Top;
headerRange1.Style.Height = 84;
#endregion
#region Print DateTime
var headerRangeDateTimeVal = XLsheet.Range[XLsheet.Cells[excelSheetRow + 2 , ds.Tables[0].Columns.Count - 4], XLsheet.Cells[excelSheetRow+ 2, ds.Tables[0].Columns.Count]];
headerRangeDateTimeVal[1, 1] = "Print Date & Time : " + DateTime.Now.ToString("d-MMM-yyyy HH.mm.ss tt", CultureInfo.InvariantCulture);
headerRangeDateTimeVal[2, 4] = "Page " +(i+1) + " of " + totalPages;
headerRangeDateTimeVal.Font.Bold = true;
headerRangeDateTimeVal.Font.Size = 10;
headerRangeDateTimeVal.Merge(Type.Missing);
headerRangeDateTimeVal.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
#endregion
excelSheetRow = excelSheetRow + 5;
for (iCol = 0; iCol < dt.Columns.Count; iCol++)
{
range[excelSheetRow, (iCol + 1)] = iCol < 4 ? Regex.Replace(dt.Columns[iCol].ColumnName, "([a-z])_?([A-Z])", "$1 $2") : dt.Columns[iCol].ColumnName;
range.WrapText = false;
range.Font.Bold = true;
range[excelSheetRow, (iCol + 1)].Font.Size = 10;
range[excelSheetRow, (iCol + 1)].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.ColorTranslator.FromHtml("#CC99FF"));
range[excelSheetRow, (iCol + 1)].Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
range[excelSheetRow, (iCol + 1)].Borders.Color = System.Drawing.ColorTranslator.ToOle(Color.Black);
if (iCol > 3)
{
range[excelSheetRow, (iCol + 1)].Style.WrapText = true;
}
else
{
range[excelSheetRow, (iCol + 1)].Style.WrapText = false;
}
}
bool endLoop = false;
excelSheetRow = excelSheetRow + 1;
for (iRow = i * pageSize; iRow < (i + 1) * pageSize; iRow++)
{
for (iCol = 0; iCol < dt.Columns.Count; iCol++)
{
if (iRow > dt.Rows.Count-1)
{
endLoop = true;
break;
}
range[(excelSheetRow), (iCol + 1)] = dt.Rows[iRow][iCol].ToString();
range[(excelSheetRow), (iCol + 1)].Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
range[(excelSheetRow), (iCol + 1)].Borders.Color = System.Drawing.ColorTranslator.ToOle(Color.Black);
if (iCol > 3)
{
range[(excelSheetRow), (iCol + 1)].WrapText = true;
}
else
{
range[(excelSheetRow), (iCol + 1)].WrapText = false;
}
}
if(endLoop)break;
//.........这里部分代码省略.........