我想创建一个.txt文件并写入它,如果该文件已经存在,我只想添加更多行:
string path = @"E:\AppServ\Example.txt";
if (!File.Exists(path))
{
File.Create(path);
TextWriter tw = new StreamWriter(path);
tw.WriteLine("The very first line!");
tw.Close();
}
else if (File.Exists(path))
{
TextWriter tw = new StreamWriter(path);
tw.WriteLine("The next line!");
tw.Close();
}
Run Code Online (Sandbox Code Playgroud)
但是第一行似乎总是被覆盖......我怎么能避免写在同一行(我在循环中使用它)?
我知道这是一件非常简单的事情,但我WriteLine
之前从未使用过这种方法.我对C#完全不熟悉.
如何使用Windows命令行将数千个文件的扩展名更改为*****.jpg
?
我一直在寻找一段时间以及所有我见过的OCR库请求.我想知道如何实现最纯净,易于安装和使用OCR库以及安装到C#项目的详细信息.
如果可行,我只想像通常的dll参考一样实现它...
例:
using org.pdfbox.pdmodel;
using org.pdfbox.util;
Run Code Online (Sandbox Code Playgroud)
还有一个小的OCR代码示例会很好,例如:
public string OCRFromBitmap(Bitmap Bmp)
{
Bmp.Save(temppath, System.Drawing.Imaging.ImageFormat.Tiff);
string OcrResult = Analyze(temppath);
File.Delete(temppath);
return OcrResult;
}
Run Code Online (Sandbox Code Playgroud)
所以请考虑我对OCR项目并不熟悉,并给我一个答案,比如和假人交谈.
编辑: 我猜人们误解了我的要求.我想知道如何将这些开源OCR库实现到C#项目以及如何使用它们.作为dup给出的链接没有给出我要求的答案.
我正在将".jpg"文件添加到我的Excel工作表中,代码如下:
'Add picture to excel
xlApp.Cells(i, 20).Select
xlApp.ActiveSheet.Pictures.Insert(picPath).Select
'Calgulate new picture size
With xlApp.Selection.ShapeRange
.LockAspectRatio = msoTrue
.Width = 75
.Height = 100
End With
'Resize and make printable
With xlApp.Selection
.Placement = 1 'xlMoveAndSize
'.Placement = 2 'xlMove
'.Placement = 3 'xlFreeFloating
.PrintObject = True
End With
Run Code Online (Sandbox Code Playgroud)
我不知道我做错了什么,但它没有插入到正确的单元格中,所以我应该怎么做才能将这张图片放入Excel中的指定单元格?
我得到了一个动态选择的Cell,它将填充一些我将要放置的信息以及当我将信息和ENTERkeypressed放在那个Cell时;
1 - 它应该触发一个宏
'macro(value)
macro1 myinfo
Run Code Online (Sandbox Code Playgroud)
2 - 宏应该获取该单元格中的信息
myinfo = Cells( i, j )
Run Code Online (Sandbox Code Playgroud)
那我该如何实现呢?
我只想在我的picturebox.image上做一个选择,但这比一些有点烦人的情况变得更糟.我想到了主要图片框上的另一个图片框,但它对我来说似乎很懒散.我需要知道是否有一种方法可以在picturebox.image上创建一个选择区域(它将是半透明的蓝色区域),我将用鼠标绘制它并且它不应该改变我正在处理的图像.
样品:
// Start Rectangle
//
private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
// Determine the initial rectangle coordinates...
RectStartPoint = e.Location;
Invalidate();
}
// Draw Rectangle
//
private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;
Point tempEndPoint = e.Location;
Rect =
new Rectangle(
Math.Min(RectStartPoint.X, tempEndPoint.X),
Math.Min(RectStartPoint.Y, tempEndPoint.Y),
Math.Abs(RectStartPoint.X - tempEndPoint.X),
Math.Abs(RectStartPoint.Y - tempEndPoint.Y));
Invalidate(Rect);
}
// Draw Area
//
private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
// Draw the rectangle...
if (pictureBox1.Image != null)
{ …
Run Code Online (Sandbox Code Playgroud) 这是我用Razor的jQuery代码:
$("#GroupC_grup_name").attr('value', '@foreach (SelectListItem sel in (SelectList)ViewData["Gruplar"]){ @sel.Text }')
$("#GroupC_id").attr('value', '@foreach(SelectListItem sel in (SelectList)ViewData["Gruplar"]){ @sel.Value }')
Run Code Online (Sandbox Code Playgroud)
我想把它们合并在一起,因为我不想再打电话ViewData["Gruplar"]
两次.
我可以这样做吗?
@foreach(SelectListItem sel in (SelectList)ViewData["Gruplar"]){
@:$("#GroupC_grup_name").attr('value', '@sel.Text');
@:$("#GroupC_id").attr('value', '@sel.Value');
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了我能想到的一切,但仍然无法达到我想要的效果.
我正在研究一个显示如何动态调整div大小的代码。但是,代码停留在1个元素上,我做了一些工作以将其转换为多个div缩放器。
现在,在调整大小时,鼠标和div之间会出现一个空格,我的目标是确保根据父位置准确地调整每个元素的大小,使其具有确切的鼠标位置。任何会改变我观点的方法都适用。也可以不绑定到调整大小节点,而是直接保留div边框。
到目前为止,我已经完成的事情:
-通过鼠标位置调整了多个div的大小。
-在功能中保留第一个位置信息。
-孩子和父母之间的累计差异。
我想实现的目标:
-确保在调整大小时,保持器保持在鼠标位置下,而鼠标和div之间没有任何空间。
经过几次尝试调整大小后,我看到由父元素的页边距,填充...等引起的空间出现。div开始调整大小,并在div和鼠标位置之间留出一个空格。
我需要在计算中使用递归解决方案来正确调整div的大小和位置。
可能是另一种方法可以用来仅计算父级内部的x,y,w,h,但我需要一些有关如何使用鼠标来实现的解释。
function resizeable() {
var resizers = document.querySelectorAll('.n, .s, .w, .e, .nw, .ne, .se, .sw');
const min = 40;
for (let i = 0; i < resizers.length; i++) {
const currentResizer = resizers[i];
const element = currentResizer.parentElement;
const parent = currentResizer.parentElement.parentElement;
let p;
let c;
let original_w = 0;
let original_h = 0;
let parent_x = 0;
let parent_y = 0;
let child_x = 0;
let child_y = 0;
let …
Run Code Online (Sandbox Code Playgroud)我将文件作为.jpg图片扫描到一个文件夹中,我想在C#中连续为该文件夹中的每个文件进行OCR.到目前为止我做到了这一点:
public string CheckFilesAndDoOCR(string directoryPath)
{
directoryPath = Environment.SpecialFolder.MyPictures + "\\OCRTempPictures\\";
IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator();
string TheTxt = "";
while (files.MoveNext())
{
// FileInfo
FileInfo nfo = new FileInfo(Convert.ToString(files.Current));
// Get new file name
string fileName = AlltoJPG(nfo);
// FileInfo (New File)
FileInfo foo = new FileInfo(fileName);
// Check for JPG File Format
if (foo.Extension == ".jpg" || foo.Extension == ".JPG")
// or // ImageFormat.Jpeg.ToString()
{
try
{
// OCR Operations...
MODI.Document md = new MODI.Document();
md.Create(foo.FullName);
md.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false); …
Run Code Online (Sandbox Code Playgroud) 我正在通过“ sololearn”和udemy课程尝试学习C#。我正在尝试挑战,但无法弄清楚下面的代码如何与32结合使用(因为32是此处的正确答案,我试图找出原因)。有人可以向我解释这个过程吗,我认为调用自身的方法正在抛出我。
static double Pow(double x, int y)
{
if (y == 0)
{
return 1.0;
}
else
{
return x * Pow(x, y - 1);
}
}
static void Main()
{
Console.Write(Pow(2, 5));
}
Run Code Online (Sandbox Code Playgroud)
请原谅我的编码错误。我正在尝试在移动设备上执行此操作,这很困难,答案是32。有人可以解释为什么吗?
编辑:这里的道歉是我的工作方式。将2和5传递给Pow,检查是否y == 0
为假,现在它是有效的,y == 5
因此x * pow(x, y-1)
公式将处于活动状态。X仍然是2,y现在是4,这意味着它再次无法检查是否等于0,此循环一直进行到返回1.0,x一直保持在2 2 * 1.0 = 2
而不是32?