public static void WriteFormula(MSExcel._Workbook _excelDoc, int sheetIndex, ExcelPosition position, string wValue, out bool success) { if (_excelDoc != null) { try { MSExcel.Range _excelRge = GetRange(_excelDoc, sheetIndex, position); _excelRge.FormulaLocal = wValue; success = true; return; } catch (Exception ex) { success = false; Log.LogHelper.AddLog(@"异常36", ex.Message, true); Log.LogHelper.AddLog(@"异常37", " " + ex.TargetSite.ToString(), true); return; } } else { success = false; Log.LogHelper.AddLog(@"异常38", @"文件没有正常打开,无法读取数据", true); return; } }
public static void WriteValue(MSExcel._Workbook _excelDoc, int sheetIndex, ExcelPosition position, string wValue, string numberFormat, out bool success) { if (_excelDoc != null) { try { bool checkSta = true; MSExcel.Worksheet _excelSht = (MSExcel.Worksheet)_excelDoc.Worksheets[sheetIndex]; _excelSht.Cells[position.RowIndex, position.ColumnIndex] = wValue; if (!string.IsNullOrWhiteSpace(numberFormat)) { MSExcel.Range _excelRge = GetRange(_excelDoc, sheetIndex, position); _excelRge.NumberFormatLocal = numberFormat; } success = checkSta; return; } catch (Exception ex) { success = false; Log.LogHelper.AddLog(@"异常33", ex.Message, true); Log.LogHelper.AddLog(@"异常34", " " + ex.TargetSite.ToString(), true); return; } } else { success = false; Log.LogHelper.AddLog(@"异常35", @"文件没有正常打开,无法读取数据", true); return; } }
public static string GetText(MSExcel._Workbook _excelDoc, int sheetIndex, ExcelPosition position) { try { MSExcel.Range _excelRge = GetRange(_excelDoc, sheetIndex, position); return(_excelRge.Text.ToString()); } catch { return(""); } }
internal ExcelDrawing(ExcelDrawings drawings, XmlNode node, string nameXPath) : base(drawings.NameSpaceManager, node) { _drawings = drawings; _topNode = node; XmlNode posNode = node.SelectSingleNode("xdr:from", drawings.NameSpaceManager); if (node != null) { From = new ExcelPosition(posNode, drawings.NameSpaceManager); } posNode = node.SelectSingleNode("xdr:to", drawings.NameSpaceManager); if (node != null) { To = new ExcelPosition(posNode, drawings.NameSpaceManager); } _nameXPath = nameXPath; }
internal ExcelDrawing(ExcelDrawings drawings, XmlNode node, string nameXPath) : base(drawings.NameSpaceManager, node) { _drawings = drawings; _topNode = node; _id = drawings.Worksheet.Workbook._nextDrawingID++; XmlNode posNode = node.SelectSingleNode("xdr:from", drawings.NameSpaceManager); if (node != null) { From = new ExcelPosition(drawings.NameSpaceManager, posNode); } posNode = node.SelectSingleNode("xdr:to", drawings.NameSpaceManager); if (node != null) { To = new ExcelPosition(drawings.NameSpaceManager, posNode); } _nameXPath = nameXPath; SchemaNodeOrder = new string[] { "from", "to", "graphicFrame", "sp", "clientData" }; }
public static void WriteImage(MSExcel._Workbook _excelDoc, int sheetIndex, ExcelPosition position, string personPath, float PictuteWidth, float PictureHeight) { if (_excelDoc != null) { try { MSExcel.Worksheet _excelSht = (MSExcel.Worksheet)_excelDoc.Worksheets[sheetIndex]; MSExcel.Range _excelRge = GetRange(_excelDoc, sheetIndex, position); _excelRge.Select(); if (PictuteWidth < 1 || PictureHeight < 1) { MSExcel.Pictures pics = (MSExcel.Pictures)_excelSht.Pictures(Missing.Value); pics.Insert(personPath, Missing.Value); } else { float PicLeft = Convert.ToSingle(_excelRge.Left); float PicTop = Convert.ToSingle(_excelRge.Top); _excelSht.Shapes.AddPicture(personPath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, PicLeft, PicTop, PictuteWidth, PictureHeight); } return; } catch (Exception ex) { Log.LogHelper.AddLog(@"异常130", ex.Message, true); Log.LogHelper.AddLog(@"异常131", " " + ex.TargetSite.ToString(), true); return; } } else { Log.LogHelper.AddLog(@"异常32", @"文件没有正常打开,无法读取数据", true); return; } }
internal ExcelDrawing(ExcelDrawings drawings, XmlNode node, string nameXPath) : base(drawings.NameSpaceManager, node) { _drawings = drawings; _topNode = node; _id = drawings.Worksheet.Workbook._nextDrawingID++; XmlNode posNode = node.SelectSingleNode("xdr:from", drawings.NameSpaceManager); if (node != null) { From = new ExcelPosition(drawings.NameSpaceManager, posNode); } posNode = node.SelectSingleNode("xdr:to", drawings.NameSpaceManager); if (node != null) { To = new ExcelPosition(drawings.NameSpaceManager, posNode); } else { To = null; } _nameXPath = nameXPath; SchemaNodeOrder = new string[] { "from", "to", "graphicFrame", "sp", "clientData" }; }
public static string GetValueText(MSExcel._Workbook _excelDoc, int sheetIndex, ExcelPosition position) { MSExcel.Range _excelRge = GetRange(_excelDoc, sheetIndex, position); if (_excelRge != null) { return(_excelRge.Value2.ToString()); } else { return(""); } }
public static MSExcel.Range GetRange(MSExcel._Workbook _excelDoc, int sheetIndex, ExcelPosition position1, ExcelPosition position2) { if (_excelDoc != null) { if (position1.IsValid && position2.IsValid) { MSExcel.Worksheet _excelSht = (MSExcel.Worksheet)_excelDoc.Worksheets[sheetIndex]; MSExcel.Range _excelRge = (MSExcel.Range)_excelSht.Cells.get_Range(position1, position2); return(_excelRge); } else { Log.LogHelper.AddLog(@"异常26", @"读取数据时传入了错误的位置坐标:" + position1, true); return(null); } } else { Log.LogHelper.AddLog(@"异常27", @"文件没有正常打开,无法读取数据", true); return(null); } }
public static MSExcel.Range GetRange(MSExcel._Workbook _excelDoc, int sheetIndex, ExcelPosition position) { return(GetRange(_excelDoc, sheetIndex, position, position)); }
public static string GetMergedContent(MSExcel._Workbook _excelDoc, int sheetIndex, ExcelPosition position1, ExcelPosition position2, string[] titles) { string temp_text1 = GetText(_excelDoc, sheetIndex, position1).Replace(@":", ":").Replace(@" ", ""); string temp_text2 = GetText(_excelDoc, sheetIndex, position2).Replace(@":", ":").Replace(@" ", ""); if (!temp_text1.Equals("")) { foreach (string item in titles) { if (temp_text1.Equals(item)) { if (temp_text2 != "") { return(temp_text2); } else { return("/"); } } else { return(temp_text1.Replace(item, "").Trim()); } } } string text = temp_text1 + temp_text2; foreach (string item in titles) { if (text.StartsWith(item)) { text = text.Replace(item, "").Trim(); if (text != "") { return(text); } else { return("/"); } } } return(""); }
public static string GetMergedContent(MSExcel._Workbook _excelDoc, int sheetIndex, ExcelPosition position1, ExcelPosition position2, string title) { return(GetMergedContent(_excelDoc, sheetIndex, position1, position2, new string[] { title })); }