W

로컬 텍스트 엑셀 파일 읽기/쓰기

· 16년 전 · 5415

익스플로우의 보안에 허용만 가능하면 자바스크립트 상에서도 읽기/쓰기가 가능하다.

 

우선 text파일 읽고 쓰는 예제이다.(C:\\book1.txt를 읽고 씀)

 

=====================================================================================================================

<html>
<head>
<title>file save/load</title>

 

<script type="text/javascript">

    var fso=new ActiveXObject("Scripting.FileSystemObject");
    var filename="C:\\book1.txt";
    function savefile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,2,true);
        f.Write(myarea.innerHTML);
        f.Close();
    }
   
    function loadfile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,1);
        r=f.ReadAll();
        f.Close();
        myarea.innerHTML=r;
    }
   
   
    //function window.onload() {
    //    loadfile(filename);
    //}
</script>


</head>
<body>
 <table>
  <tr>
   <td>
    <div id=myarea contenteditable=true style="width:320;height:240;border:solid 2 inset;overflow:scroll;background-color:silver;"></div>
    <br><input type=button value=load onclick=loadfile()><input type=button value=save onclick=savefile()>
   </td>
  </tr>
 </table>
</form>
</body>
</html>

 

======================================Excel 파일 열고 쓰기 =================================================

- 쓰기 -

<script type="text/javascript">

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\book1.xls");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();
</script>

 

- 열기 -

function StartExcel() {
var oExcel;

var oWBook;
oExcel = new ActiveXObject("Excel.Application");

oExcel.Visible = true;

oExcel.workbooks.open("C:/test.xls");

oExcel.Quit();

oExcel = null;
}

 

간단한 파일 읽기의 경우 상당히 유용할 수 있겠다..

 
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
15년 전 조회 1,878
15년 전 조회 687
15년 전 조회 1,174
15년 전 조회 1,148
15년 전 조회 2,932
15년 전 조회 3,258
15년 전 조회 1,929
15년 전 조회 1,435
15년 전 조회 2,051
15년 전 조회 1,564
15년 전 조회 1,161
15년 전 조회 3,858
15년 전 조회 1,496
15년 전 조회 1,595
15년 전 조회 2,823
15년 전 조회 1,514
15년 전 조회 4,250
15년 전 조회 2,458
15년 전 조회 3,232
15년 전 조회 1,852
15년 전 조회 2,083
15년 전 조회 1,380
15년 전 조회 4,454
15년 전 조회 4,043
15년 전 조회 3,867
15년 전 조회 5,280
15년 전 조회 3,510
15년 전 조회 1,887
15년 전 조회 1,832
15년 전 조회 1,968
15년 전 조회 1,679
15년 전 조회 4,074
15년 전 조회 3,000
15년 전 조회 2,164
16년 전 조회 1,752
16년 전 조회 1,980
16년 전 조회 2,470
16년 전 조회 1,547
16년 전 조회 2,484
16년 전 조회 1,813
16년 전 조회 1,920
16년 전 조회 1,564
16년 전 조회 2,268
16년 전 조회 1,591
16년 전 조회 2,006
16년 전 조회 2,195
16년 전 조회 1,260
16년 전 조회 1,332
16년 전 조회 1,979
16년 전 조회 5,416
16년 전 조회 1,717
16년 전 조회 2,240
16년 전 조회 2,434
16년 전 조회 1,586
16년 전 조회 1,376
16년 전 조회 2,307
16년 전 조회 5,017
16년 전 조회 2,290
16년 전 조회 2,945
16년 전 조회 1,832
16년 전 조회 3,674
16년 전 조회 4,517
16년 전 조회 3,172
16년 전 조회 2,424
16년 전 조회 2,520
16년 전 조회 2,755
16년 전 조회 2,255
16년 전 조회 5,592
16년 전 조회 3,445
16년 전 조회 1,441
16년 전 조회 1,783
16년 전 조회 5,151
16년 전 조회 2,394
16년 전 조회 3,487
16년 전 조회 2,730
16년 전 조회 1,639
16년 전 조회 5,446
16년 전 조회 2,550
16년 전 조회 6,044
16년 전 조회 2,020
16년 전 조회 4,097
16년 전 조회 3,113
16년 전 조회 2,300
16년 전 조회 2,314
16년 전 조회 4,456
16년 전 조회 3,378
16년 전 조회 2,903
16년 전 조회 3,049
16년 전 조회 2,168
16년 전 조회 1,852
16년 전 조회 1,767
16년 전 조회 1,486
16년 전 조회 1,756
16년 전 조회 1,983
16년 전 조회 1,676
16년 전 조회 4,918
16년 전 조회 3,905
16년 전 조회 1,873
16년 전 조회 1,618
16년 전 조회 2,360